Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Substitution-cipher/Python/substitution-cipher-1.py
Normal file
19
Task/Substitution-cipher/Python/substitution-cipher-1.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from string import printable
|
||||
import random
|
||||
|
||||
EXAMPLE_KEY = ''.join(sorted(printable, key=lambda _:random.random()))
|
||||
|
||||
def encode(plaintext, key):
|
||||
return ''.join(key[printable.index(char)] for char in plaintext)
|
||||
|
||||
def decode(plaintext, key):
|
||||
return ''.join(printable[key.index(char)] for char in plaintext)
|
||||
|
||||
original = "A simple example."
|
||||
encoded = encode(original, EXAMPLE_KEY)
|
||||
decoded = decode(encoded, EXAMPLE_KEY)
|
||||
print("""The original is: {}
|
||||
Encoding it with the key: {}
|
||||
Gives: {}
|
||||
Decoding it by the same key gives: {}""".format(
|
||||
original, EXAMPLE_KEY, encoded, decoded))
|
||||
7
Task/Substitution-cipher/Python/substitution-cipher-2.py
Normal file
7
Task/Substitution-cipher/Python/substitution-cipher-2.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
The original is: A simple example.
|
||||
Encoding it with the key: dV1>r7:TLlJa<EFBFBD>uY o]MjH\hI^X cPN#!fmv[
|
||||
<e=04|O'~{y$bAq@}U.WtF*)x/K?
|
||||
Q%S(<EFBFBD>RB;25&s6Z9C3+D-_8kn,`Egiwzp"G
|
||||
Gives:
|
||||
iPMhX\YiYmJhX\Y5
|
||||
Decoding it by the same key gives: A simple example.
|
||||
Loading…
Add table
Add a link
Reference in a new issue