def test_sample3(self): hc128.init("0F62B5085BAE0154A7FA4DA0F34699EC", "288FF65DC42B92F960C72E95FC63CA31") hc128.i = 0 out = "1cd8aeddfe52e217e835d0b7e84e2922d04b1adbca53c4522b1aa604c42856a90af83e2614bce65c0aecabdd8975b55700d6a26d52fff0888da38f1de20b77b7" for i in range(0, 8): self.assertEquals(out[i * 8:i * 8 + 8], hc128.keygen())
def test_sample1(self): hc128.init("00000000000000000000000000000000", "00000000000000000000000000000000") hc128.i = 0 out = "82001573a003fd3b7fd72ffb0eaf63aac62f12deb629dca72785a66268ec758b1edb36900560898178e0ad009abf1f491330dc1c246e3d6cb264f6900271d59c" for i in range(0, 8): self.assertEquals(out[i * 8:i * 8 + 8], hc128.keygen())
def test_sample2(self): hc128.init("0558ABFE51A4F74A9DF04396E93C8FE2", "00000000000000000000000000000000") hc128.i = 0 out = "54182309bd782dee44fb59b0ec6949202b372af8d715271a96d87867e65a067fa5e52b455b76d400537b5d47c4ac318eee4c2abe29f56107c213071c85828605" for i in range(0, 8): self.assertEquals(out[i * 8:i * 8 + 8], hc128.keygen())
def hcDecrypt(): start_time = time() text = txt key = (hc128_password.get()).encode("hex") IV = key global hc_join n = 8 ii = 0 x = [] res = "" for c in text: if (ii % n == 0): if (ii == 0): res += c else: x.append(res) res = "" res += c else: res += c ii = ii + 1 x.append(res) print(x) print("Key = " + key) print("IV = " + IV) hc128.init(key, IV) hc128.i = 0 k = hc128.keygen() print("Keystream generated: " + k) k = k.decode("hex") hc_arr = [] for hc_chiper_res in x: print(hc_chiper_res) hc_chiper_res = hc_chiper_res.decode("hex") plain_text = "" for i in range(0, 4): plain_text += chr(ord(hc_chiper_res[i]) ^ ord(k[i])) plain_text = plain_text.encode("hex") hc_arr.append(plain_text) print("Decrypt plain text: " + plain_text) hc_join = "".join(hc_arr) print(hc_join) messagebox.showinfo("Success", "Decrypt HC-128 Success") end_time = time() time_taken = end_time - start_time hours, rest = divmod(time_taken, 3600) minutes, seconds = divmod(rest, 60) print("Time taken:", format_timespan(end_time - start_time))
def hcEncrypt(): start_time = time() text = twofish_encrypted_message key = (hc128_password.get()).encode("hex") IV = key global hc_join n = 8 ii = 0 x = [] res = "" for c in text: if (ii % n == 0): if (ii == 0): res += c else: x.append(res) res = "" res += c else: res += c ii = ii + 1 x.append(res) print(x) print("Key = " + key) print("IV = " + IV) hc128.init(key, IV) k = hc128.keygen() print("Keystream generated: " + k) k = k.decode("hex") hc_array = [] for twofish_chiper_res in x: print(twofish_chiper_res) twofish_chiper_res = twofish_chiper_res.decode('hex') cipher_text = "" for i in range(0, 4): cipher_text += chr(ord(twofish_chiper_res[i]) ^ ord(k[i])) cipher_text = cipher_text.encode("hex") hc_array.append(cipher_text) print("Encrypted cipher text: " + cipher_text) hc_join = "".join(hc_array) print("cipher hc-128: ", hc_join) messagebox.showinfo("Success", "Encrypt HC-128 Success") end_time = time() time_taken = end_time - start_time hours, rest = divmod(time_taken, 3600) minutes, seconds = divmod(rest, 60) print("Time taken:", format_timespan(end_time - start_time))
import hc128 key = "0F62B5085BAE0154A7FA4DA0F34699EC" IV = "288FF65DC42B92F960C72E95FC63CA31" print "Initializing HC-128 cipher state" print "Key = " + key print "IV = " + IV hc128.init(key, IV) print "\nHC-128 Cipher state initialized" while True: plain_text = raw_input("\nEnter plain text(in hex bytes, 4 at a time) to encrypt: ") if len(plain_text) != 8: break print "\nGenerating keystream, 4 bytes at a time" k = hc128.keygen() print "Keystream generated: " + k plain_text = plain_text.decode("hex") k = k.decode("hex") cipher_text = "" for i in range(0, 4): cipher_text += chr(ord(plain_text[i]) ^ ord(k[i])) cipher_text = cipher_text.encode("hex")
def test_sample1(self): hc128.init("00000000000000000000000000000000", "00000000000000000000000000000000") hc128.i = 0 out = "82001573a003fd3b7fd72ffb0eaf63aac62f12deb629dca72785a66268ec758b1edb36900560898178e0ad009abf1f491330dc1c246e3d6cb264f6900271d59c" for i in range(0, 8): self.assertEquals(out[i*8:i*8 + 8], hc128.keygen())
def test_sample3(self): hc128.init("0F62B5085BAE0154A7FA4DA0F34699EC", "288FF65DC42B92F960C72E95FC63CA31") hc128.i = 0 out = "1cd8aeddfe52e217e835d0b7e84e2922d04b1adbca53c4522b1aa604c42856a90af83e2614bce65c0aecabdd8975b55700d6a26d52fff0888da38f1de20b77b7" for i in range(0, 8): self.assertEquals(out[i*8:i*8 + 8], hc128.keygen())
def test_sample2(self): hc128.init("0558ABFE51A4F74A9DF04396E93C8FE2", "00000000000000000000000000000000") hc128.i = 0 out = "54182309bd782dee44fb59b0ec6949202b372af8d715271a96d87867e65a067fa5e52b455b76d400537b5d47c4ac318eee4c2abe29f56107c213071c85828605" for i in range(0, 8): self.assertEquals(out[i*8:i*8 + 8], hc128.keygen())
import hc128 key = "0F62B5085BAE0154A7FA4DA0F34699EC" IV = "288FF65DC42B92F960C72E95FC63CA31" print "Initializing HC-128 cipher state" print "Key = " + key print "IV = " + IV hc128.init(key, IV) print "\nHC-128 Cipher state initialized" while True: plain_text = raw_input( "\nEnter plain text(in hex bytes, 4 at a time) to encrypt: ") if len(plain_text) != 8: break print "\nGenerating keystream, 4 bytes at a time" k = hc128.keygen() print "Keystream generated: " + k plain_text = plain_text.decode("hex") k = k.decode("hex") cipher_text = "" for i in range(0, 4): cipher_text += chr(ord(plain_text[i]) ^ ord(k[i]))