Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 51k
Create vernam_cipher.py#10702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Create vernam_cipher.py #10702
Changes from all commits
8ce27f1f5e8dffc8aae7e44efe0794f67687e19ac6f25c0d0ee52bdf59559047d8e29ba0e9cf564ebf3158b9743720df35a5a67980aef0ffc2aa8d42181ab058581b4a92771efa852330dcffecb5cc608ce28b1c0963c95c1d6adb2a8db25fb59599322854c88c87cfff89e783901e65c1d504fd68ac5e33b903c68c314b4ce0a29eb4062c7e2346cd6bc1d7bd8ac7f3e5078ee2871097058daf8ae99814016a43bae9f65File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| def vernam_encrypt(plaintext: str, key: str) -> str: | ||
cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. Anupamaraie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| >>> vernam_encrypt("HELLO","KEY") | ||
| 'RIJVS' | ||
| """ | ||
| ciphertext = "" | ||
| for i in range(len(plaintext)): | ||
| ct = ord(key[i % len(key)]) - 65 + ord(plaintext[i]) - 65 | ||
| while ct > 25: | ||
| ct = ct - 26 | ||
| ciphertext += chr(65 + ct) | ||
| return ciphertext | ||
| def vernam_decrypt(ciphertext: str, key: str) -> str: | ||
cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. Anupamaraie marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. cclauss marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| """ | ||
| >>> vernam_decrypt("RIJVS","KEY") | ||
| 'HELLO' | ||
| """ | ||
| decrypted_text = "" | ||
| for i in range(len(ciphertext)): | ||
| ct = ord(ciphertext[i]) - ord(key[i % len(key)]) | ||
| while ct < 0: | ||
| ct = 26 + ct | ||
| decrypted_text += chr(65 + ct) | ||
| return decrypted_text | ||
| if __name__ == "__main__": | ||
| from doctest import testmod | ||
| testmod() | ||
| # Example usage | ||
| plaintext = "HELLO" | ||
| key = "KEY" | ||
| encrypted_text = vernam_encrypt(plaintext, key) | ||
| decrypted_text = vernam_decrypt(encrypted_text, key) | ||
| print("\n\n") | ||
| print("Plaintext:", plaintext) | ||
| print("Encrypted:", encrypted_text) | ||
| print("Decrypted:", decrypted_text) | ||
Uh oh!
There was an error while loading. Please reload this page.