Пример #1
0
def sanitizeKey(key):
    sanitizedKey = ""
    for y in range(len(key)):
        if key[y].isalpha():
            sanitizedKey += key[y]
    sanitizedKey = toNum(sanitizedKey)
    return sanitizedKey
Пример #2
0
    def setList(self, i_strHourList):
        self.m_List = []

        tmp_lists = i_strHourList.split(",")

        for i in range(len(tmp_lists)):
            self.m_List.append(common.toNum(tmp_lists[i]))
Пример #3
0
def decrypt(shift, ciphertext):
    temp = toNum(ciphertext)
    plaintext = []
    for i in temp:
        i -= shift
        i %= 26
        plaintext.append(i)
    return toLetter(plaintext)
Пример #4
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)
Пример #5
0
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."
Пример #6
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)
Пример #7
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)
Пример #8
0
    def exist(self, i_nVal):
        if '*' in self.m_List:
            return True

        l_nVal = common.toNum(i_nVal)

        if len(self.m_List) > 0:
            retVal = l_nVal in self.m_List

        if l_nVal >= self.m_From and l_nVal <= self.m_To:
            retVal = True

        return retVal
Пример #9
0
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)