Exemplo n.º 1
0
 def rsaDecode(Ciphertext, d, n):
     C = int(Ciphertext)
     M = str(bin(C**d % n))[2:]
     while len(M) < 8:
         M = "0" + M
     Plaintext = Tools.AsciiToString(M)
     return Plaintext
Exemplo n.º 2
0
 def Group_desDecode(Ciphertext):
     Ciphertext_ascii = Tools.stringToAscii(Ciphertext)
     global ZeroNum
     GroupNum = len(Ciphertext_ascii) // 64
     Ciphertext_G = []
     for i in range(0, GroupNum):
         Ciphertext_G.append(Ciphertext_ascii[64 * i:64 * (i + 1)])
     Plaintext_ascii = ""
     for i in Ciphertext_G:
         Plaintext_G = DES.desDecode(i)
         Plaintext_ascii += Plaintext_G
     Plaintext_ascii = Plaintext_ascii[0:(len(Plaintext_ascii) - ZeroNum)]
     Plaintext = Tools.AsciiToString(Plaintext_ascii)
     Plaintext = codecs.escape_decode(Plaintext)[0]
     Plaintext = Plaintext.decode("utf8")
     return Plaintext
Exemplo n.º 3
0
 def desEncode(Plaintext, keyseed):
     init_ip = init_IP.init_IP(Plaintext)
     L = init_ip[0:32]
     R = init_ip[32:64]
     global Key
     for i in range(1, 17):
         key = GetKeys.GetKeys(keyseed, i)
         K, keyseed = key.split(",")
         Key.append(K)
         L_ = R
         after_F = F_fanc.F_fanc(R, K)
         F_int = int(after_F, 2)
         L_int = int(L, 2)
         R_ = str(bin(F_int ^ L_int).split("0b")[1])
         while R_.__len__() < 32:
             R_ = "0" + R_
         L = L_
         R = R_
     msg = R + L
     Ciphertext_ascii = IV_IP.IV_IP(msg)
     Ciphertext = Tools.AsciiToString(Ciphertext_ascii)
     return Ciphertext