Exemplo n.º 1
0
def encipherText(text,key):
    r = len(key)
    lst = []
    for i in range(len(text)):
        lst.append((alph.alphToCode(text[i])+alph.alphToCode(key[i%r]))%alph.m)
    enciphered = ''
    for i in lst:
        enciphered += alph.codeToAlph(i)
    return enciphered
Exemplo n.º 2
0
def decryptBlock(block):
    letters = {}
    for i in block:
        if letters.has_key(i):
            letters[i] +=1
        else:
            letters[i] = 1
    y = alph.alphToCode(sorted(letters.items(), key = operator.itemgetter(1))[-1:][0][0])
    x = alph.alphToCode(alph.most_frequent[0])
    k = findK(x,y)
    decryptedBlock = []
    for i in block:
        yCode = alph.alphToCode(i)
        letter = (yCode - k) % alph.m
        decryptedBlock.append(alph.codeToAlph(letter))
    return (decryptedBlock, alph.codeToAlph(k))
Exemplo n.º 3
0
def dec(key,text):
    newText =''
    for i in range(len(text)):
        x = (alph.alphToCode(text[i]) - alph.alphToCode(key[i % 17])) % alph.m
        newText += alph.codeToAlph(x)
    return newText
Exemplo n.º 4
0
def calcD(text,j,n):
    d = 0
    for i in range(n):
        d += kronecker(alph.alphToCode(text[i]),alph.alphToCode(text[(i+j)%n]))
    if d > 300:
        print "j = %d D = %d ||" % (j,d)