print("hello world")
hello world
print("hello world")
hello world
%
%ls
cipher.html cipher.qmd cipher.quarto_ipynb cipher_files/
= lambda e, d: (e,d) cipher
e
is the encryption function.
k
m
c
= lambda k, m: ""
e
= 'key'
k = 'msg'
m
= e(k,m) c
d
is the decryption function.
k
c
m
, that is equal to original message.= lambda k, c: ""
d
# c is previously defined
= d(k,c) m_out
= ""
m assert(d(k,e(k,m)) == m)
= lambda k: lambda m: ""
make_f
= 'key'
k = 'msg'
m
= make_f(k)
e
= e(m) c
= make_f(k)
d
= d(c) m_out
= "", make_f(k), make_f(k)
m, e, d
assert(d(e(m)) == m)
= ""
m assert((make_f(k))((make_f(k))(m)) == m)
= [ # rotors
rs "BDFHJLCPRTXVZNYEIWGAKMUSQO", # fast
"AJDKSIRUXBLHWTMCQGZNPYFVOE", # medium
"EKMFLGDQVZNTOWYHXUSPAIBRCJ", # slow
"IXUHFEZDAOMTKQJWNSRLCYPBVG" # reflect
]
= rs[0] r
= lambda k : lambda a : "" make_f
E
_____|______________________
[ ABCDEFGHIJKLMNOPQRSTUVWXYZ ] # alphabet
[ | ]
[ BDFHJLCPRTXVZNYEIWGAKMUSQO ] # cipher
‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ J
= "ABCDEFGHIJKLMNOPQRSTUVWXYZ" abcs
"E") abcs.index(
4
4] r[
'J'
make_f
= lambda k : lambda a : k[abcs.index(a)] make_e
= make_e(r) e
e
?print("e ->", e, "\ntype(e) -> ", type(e))
e -> <function <lambda>.<locals>.<lambda> at 0x7ff95025f130>
type(e) -> <class 'function'>
e
to some letter, such as “E”"E") e(
'J'
d
?
J
_____|______________________
[ BDFHJLCPRTXVZNYEIWGAKMUSQO ] # cipher
[ | ]
[ ABCDEFGHIJKLMNOPQRSTUVWXYZ ] # alphabet
‾‾‾‾‾|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ E
= lambda k : lambda a : abcs[k.index(a)] make_d
= make_d(r) d
d
print("d ->", d, "\ntype(d) -> ", type(d))
d -> <function <lambda>.<locals>.<lambda> at 0x7ff95025f760>
type(d) -> <class 'function'>
d
to some letter, such as “J”"J") d(
'E'
= 'E'
m assert(d(e(m)) == m)
assert(all([d(e(m)) == m for m in abcs]))
assert(all([all([make_d(r)(make_e(r)(m)) == m for m in abcs]) for r in rs]))