Example #1
0
def sanitizeKey(key):
    sanitizedKey = ""
    for y in range(len(key)):
        if key[y].isalpha():
            sanitizedKey += key[y]
    sanitizedKey = toNum(sanitizedKey)
    return sanitizedKey
Example #2
0
def decrypt(shift, ciphertext):
    temp = toNum(ciphertext)
    plaintext = []
    for i in temp:
        i -= shift
        i %= 26
        plaintext.append(i)
    return toLetter(plaintext)
Example #3
0
def encrypt(radius, plaintext):
  temp = toNum(plaintext)
  ciphertext = []
  j = 0
  while i =< radius:
    while j < plaintext
    i %= 26
    ciphertext.append(i)
  return toLetter(ciphertext)
Example #4
0
File: affine.py Project: 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."
Example #5
0
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)
Example #6
0
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)
Example #7
0
File: affine.py Project: 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)