def db_setter(text, key): global x1 global x2 x1 = caesar.encode(text,key) x2 = caesar.decode(x1,key)
def test_decode(self): self.assertEqual(caesar.decode("zabc", -1), "abcd") self.assertEqual(caesar.decode("bcde", 1), "abcd") self.assertEqual(caesar.decode("cdiwxcv", -999), "nothing") self.assertEqual(caesar.decode("yzestyr", 999), "nothing") self.assertEqual(caesar.decode("anything", 26), "anything") self.assertEqual(caesar.decode("anything", -26), "anything")
def receive(): """Handles receiving of messages.""" while True: try: msg = client_socket.recv(BUFSIZE).decode("utf8") global msg_count last_index: int = msg.find(":") + 2 name = msg[:last_index] message = msg[last_index:] if msg_count >= 2: message = rle.decompress(message) print(message) message = caesar.decode(message, 3) print(message) else: msg_count += 1 msg_list.insert(tkinter.END, name + message) except OSError: # Possibly client has left the chat. break
"F": 1.66 / 100, "K": 1.21 / 100, "Z": 1.13 / 100, "P": 0.79 / 100, "V": 0.67 / 100, "J": 0.27 / 100, "Y": 0.04 / 100, "X": 0.03 / 100, "Q": 0.02 / 100 } code = "NRJ" decodeWithProb = [] for k in range(26): decoded = list(map(lambda x: caesar.decode(x, k, False), code)) prob = 1 for d in decoded: prob = prob * probabilities[d] decodeWithProb.append(("".join(decoded), prob, k)) decodeWithProb.sort(key=lambda x: x[1], reverse=True) probSum = 0 for _, p, _ in decodeWithProb: probSum += p for d, p, k in decodeWithProb: print("%s\t(%f%%), Key: %c" % (d, (p * 100) / probSum, chr(k + ord("A"))))
<link rel="stylesheet" href="../assets/css/yQGOJexeijQAipYU.css"> <link rel="stylesheet" href="../assets/css/FbaYSRCtRvomasKvr.css"> <link rel="stylesheet" href="../assets/css/tHnoLzeHWytJlBrhyjTP.css"> <link rel="stylesheet" href="../assets/css/JjQXzSfmtfzgphLJOwfh.css"> <link rel="stylesheet" href="../assets/css/ojtDvXjngAToaxCh.css"> <link rel="stylesheet" href="../assets/css/qjeydFqsuxHoUzfTSWbW.css"> <link rel="stylesheet" href="../assets/css/tqOolAXffGoFsAiQEL.css"> <link rel="stylesheet" href="../assets/css/CBLrZUeuNRpwoFZxetiA.css"> <link rel="stylesheet" href="../assets/css/tLPrudKCwTQQYzch.css"> <link rel="stylesheet" href="../assets/css/bKwAsDWPQSyFthAwZag.css"> <link rel="stylesheet" href="../assets/css/HpGAkKhTVrzJkTCmQUx.css"> <link rel="stylesheet" href="../assets/css/TMkcPBxGAujFcusJ.css"> <link rel="stylesheet" href="../assets/css/eTkGskwYettEFMRFzrR.css"> <link rel="stylesheet" href="../assets/css/ckkemHUQOnFQtRlLfVVb.css"> <link rel="stylesheet" href="../assets/css/UqdvWSnUYLBhdbNWskir.css"> <link rel="stylesheet" href="../assets/css/bCkkEsuAWYlxDMLcP.css"> <link rel="stylesheet" href="../assets/css/jtDBgZWGpIafLxFViIkc.css"> <link rel="stylesheet" href="../assets/css/QCrQUMfWuxkhidvYGf.css"> <link rel="stylesheet" href="../assets/css/iKLnJqUxJTTVUoop.css"> <link rel="stylesheet" href="../assets/css/kiXBnPbrCAsTKhEU.css"> <link rel="stylesheet" href="../assets/css/GGVGRjfiRrXDAVsV.css"> <link rel="stylesheet" href="../assets/css/}fLQxrIgFIcArXEXnXd.css">''' styles = re.findall("\/css\/([^.]+).css", raw) for style in styles: print("Checking {}".format(style)) for i in range(1, 27): print("{} => {}".format(i, caesar.decode(style, i))) # print(styles)
import caesar import sys text = "xipytdqgyxomprhanfllmwvlgeigahhqgyxoqgiheaeotqbkulpqpldzxhotfbyhkemdploqgotlzgutnpilplkjzxyakuwfvfzvsqerxtpphnqlklkpqul" if len(sys.argv) < 2: print("usage: %s key..." % sys.argv[0]) exit(1) for key in sys.argv[1:]: print("Key: %s\n\t" % key, end="") for index, char in enumerate(text): key_index = index % len(key) k = key[key_index] print(caesar.decode(char, ord(k) - ord("a"), True), end='') print()
def test_decode_invalid(self): self.assertEqual(decode('Gttlqj ktwjajw', 30), 'Invalid key!') self.assertEqual(decode('Gttlqj ktwjajw', 0), 'Invalid key!')
def test_decode_valid(self): self.assertEqual(decode('Gttlqj ktwjajw', 5), 'Google forever')
import socket import caesar sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) PORT = 10082 sock.bind(('', PORT)) sock.listen(100) print("listening on port" + str(PORT)) conn, addr = sock.accept() print("connected:", addr) data = conn.recvmsg(1024) print(data[0].decode()) if input("Do you want to decode this?Y/n") == "y": print(caesar.decode(data[0].decode())) else: pass
import caesar import rot13 import trithemius import vigenere print(""" ----------------------------------------------------- | CLASSICAL CRYPTOGRAPHY EXAMPLES (ENCODED & DECODED) | ----------------------------------------------------- """) print("[ CAESAR CIPHER ]") caesar_msg = "This method was used by Julius Caesar in his personal correspondence, hence it being named after him." caesar_msg_enc = caesar.encode(caesar_msg, 7) print("Cipher >>", caesar_msg_enc) caesar_msg_dec = caesar.decode(caesar_msg_enc, 7) print("Plaintext >>", caesar_msg_dec) print("About: https://en.wikipedia.org/wiki/Caesar_cipher", "\n") print("[ROT13 CIPHER]") rot13_msg = "This cipher is a variant of the Caesar Cipher in which each letter is replaced with the thirteenth letter after (or before) it. The process for encoding and decoding is exactly the same." rot13_msg_enc = rot13.encode(rot13_msg) print("Cipher >>", rot13_msg_enc) rot13_msg_dec = rot13.decode(rot13_msg_enc) print("Plaintext >>", rot13_msg_dec) print("About: https://en.wikipedia.org/wiki/ROT13", "\n") print("[TRITHEMIUS CIPHER]") trith_msg = "The Trithemius Cipher was invented by Johannes Trithemius and was outlined in his book Polygraphia, which is often considered the first published work on cryptology." trith_msg_enc = trithemius.encode(trith_msg) print("Cipher >>", trith_msg_enc)