示例#1
0
文件: scytale.py 项目: pdogg/mdbc
def decrypt(shift, ciphertext):
    temp = toNum(ciphertext)
    plaintext = []
    for i in temp:
        i -= shift
        i %= 26
        plaintext.append(i)
    return toLetter(plaintext)
示例#2
0
文件: scytale.py 项目: pdogg/mdbc
def encrypt(radius, plaintext):
  temp = toNum(plaintext)
  ciphertext = []
  j = 0
  while i =< radius:
    while j < plaintext
    i %= 26
    ciphertext.append(i)
  return toLetter(ciphertext)
示例#3
0
文件: affine.py 项目: t0ph/mdbc
def decrypt(alpha, beta, ciphertext):
    modInv = modularInverse(alpha, 26)
    if modInv != None:
        plaintext = toNum(ciphertext)
        for i in range(len(plaintext)):
            if ciphertext[i].isalpha():
                plaintext[i] = (modInv * (plaintext[i] - beta)) % 26
        return toLetter(plaintext)
    else:
        return "No MMI for " + str(alpha) + " and 26."
示例#4
0
文件: vigenere.py 项目: t0ph/mdbc
def encrypt(key, plaintext):
    ciphertext = []
    sanitizedKey = sanitizeKey(key)
    numPlaintext = toNum(plaintext)
    y = 0  # key index
    for x in range(len(plaintext)):
        if plaintext[x].isalpha():
            ciphertext.append((numPlaintext[x] + sanitizedKey[y]) % 26)
            y = (y + 1) % len(sanitizedKey)
        else:
            ciphertext.append(plainttext[x])
    return toLetter(ciphertext)
示例#5
0
文件: vigenere.py 项目: t0ph/mdbc
def decrypt(key, ciphertext):
    plaintext = []
    sanitizedKey = sanitizeKey(key)
    numCiphertext = toNum(ciphertext)
    y = 0  # key index
    for x in range(len(ciphertext)):
        if ciphertext[x].isalpha():
            plaintext.append((numCiphertext[x] - sanitizedKey[y]) % 26)
            y = (y + 1) % len(sanitizedKey)
        else:
            plaintext.append(ciphertext[x])
    return toLetter(plaintext)
示例#6
0
文件: affine.py 项目: t0ph/mdbc
def encrypt(alpha, beta, plaintext):
    ciphertext = toNum(plaintext)
    for i in range(len(ciphertext)):
        if plaintext[i].isalpha():
            ciphertext[i] = (ciphertext[i] * alpha + beta) % 26
    return toLetter(ciphertext)