Ejemplo n.º 1
0
    def decrypt(self, id, mixs, msgs):
        avcrypt = AVCrypt(bits=B)
        if self.load_key(id, avcrypt):
            k = avcrypt.k

        me = mixs[0]
        others = mixs[1:]
        last = not others
        msgs = [list(map(int, i.split(b','))) for i in msgs]
        msgs = avcrypt.shuffle_decrypt(msgs, last)

        if not last:
            msgs = b' '.join(b'%d,%d' % (a, b) for a, b in msgs)
            resp = self.mix_req(others[0], b'DECRYPT %s %s %s' %
                    (id, b','.join(others), msgs))
            return resp
        else:
            return b' '.join(b'%d' % i for i in msgs)
Ejemplo n.º 2
0
    def decrypt(self, id, mixs, msgs):
        avcrypt = AVCrypt(bits=B)
        if self.load_key(id, avcrypt):
            k = avcrypt.k

        me = mixs[0]
        others = mixs[1:]
        last = not others
        msgs = [list(map(int, i.split(b','))) for i in msgs]
        msgs = avcrypt.shuffle_decrypt(msgs, last)

        if not last:
            msgs = b' '.join(b'%d,%d' % (a, b) for a, b in msgs)
            resp = self.mix_req(
                others[0], b'DECRYPT %s %s %s' % (id, b','.join(others), msgs))
            return resp
        else:
            return b' '.join(b'%d' % i for i in msgs)
Ejemplo n.º 3
0
    def shuffle(self, id, mixs, msgs):
        avcrypt = AVCrypt(bits=B)
        pk = self.load_pk(id)

        me = mixs[0]
        others = mixs[1:]
        last = not others
        msgs = [list(map(int, i.split(b','))) for i in msgs]
        msgs = avcrypt.shuffle(msgs, pk)
        msgs = b' '.join(b'%d,%d' % (a, b) for a, b in msgs)

        epk = b'%d,%d,%d' % pk

        if not last:
            resp = self.mix_req(others[0], b'SHUFFLE %s %s %s %s' %
                    (id, b','.join(others), epk, msgs))
            return resp
        else:
            return msgs
Ejemplo n.º 4
0
    def shuffle(self, id, mixs, msgs):
        avcrypt = AVCrypt(bits=B)
        pk = self.load_pk(id)

        me = mixs[0]
        others = mixs[1:]
        last = not others
        msgs = [list(map(int, i.split(b','))) for i in msgs]
        msgs = avcrypt.shuffle(msgs, pk)
        msgs = b' '.join(b'%d,%d' % (a, b) for a, b in msgs)

        epk = b'%d,%d,%d' % pk

        if not last:
            resp = self.mix_req(
                others[0],
                b'SHUFFLE %s %s %s %s' % (id, b','.join(others), epk, msgs))
            return resp
        else:
            return msgs
Ejemplo n.º 5
0
    def gen_key(self, id, mixs, p, g):
        avcrypt = AVCrypt(bits=B)
        if self.load_key(id, avcrypt):
            k = avcrypt.k
        elif (not g or not p):
            k = avcrypt.genk()
            self.save_key(id, avcrypt)
        else:
            k = avcrypt.getk(int(p), int(g))
            self.save_key(id, avcrypt)

        me = mixs[0]
        others = mixs[1:]
        if others:
            resp = self.mix_req(others[0], b'GEN_KEY %s %s %d,%d' %
                    (id, b','.join(others), k.p, k.g))
            p, g, y = resp.split(b',')
            y = (int(y) * k.y) % k.p
            return b'%s,%s,%d' % (p, g, y)
        else:
            return b'%d,%d,%d' % (k.p, k.g, k.y)
Ejemplo n.º 6
0
    def gen_key(self, id, mixs, p, g):
        avcrypt = AVCrypt(bits=B)
        if self.load_key(id, avcrypt):
            k = avcrypt.k
        elif (not g or not p):
            k = avcrypt.genk()
            self.save_key(id, avcrypt)
        else:
            k = avcrypt.getk(int(p), int(g))
            self.save_key(id, avcrypt)

        me = mixs[0]
        others = mixs[1:]
        if others:
            resp = self.mix_req(
                others[0],
                b'GEN_KEY %s %s %d,%d' % (id, b','.join(others), k.p, k.g))
            p, g, y = resp.split(b',')
            y = (int(y) * k.y) % k.p
            return b'%s,%s,%d' % (p, g, y)
        else:
            return b'%d,%d,%d' % (k.p, k.g, k.y)
Ejemplo n.º 7
0
import sys
from avcrypt import AVCrypt
from avcrypt import ElGamal

p, g, y = map(int, sys.argv[1].split(','))
k = AVCrypt(bits=8)
k.k = ElGamal.construct((p, g, y))

clears = [2, 3, 6, 4]
cipher = [','.join(map(str, k.encrypt(i))) for i in clears]
print(' '.join(cipher))
Ejemplo n.º 8
0
import sys
from avcrypt import AVCrypt
from avcrypt import ElGamal


p, g, y = map(int, sys.argv[1].split(','))
k = AVCrypt(bits=8)
k.k = ElGamal.construct((p, g, y))

clears = [2,3,6,4]
cipher = [','.join(map(str, k.encrypt(i))) for i in clears]
print(' '.join(cipher))