Exemple #1
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))
Exemple #2
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
Exemple #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