-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
76 changed files
with
1,296 additions
and
1,099 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,93 @@ | ||
#!/usr/bin/python | ||
# -*- encoding: utf-8 -*- | ||
|
||
from secretpy import CryptMachine | ||
from secretpy import Beaufort | ||
from secretpy import alphabets | ||
from secretpy import Beaufort, CryptMachine, alphabets as al | ||
from secretpy.cmdecorators import SaveAll | ||
|
||
|
||
def encdec(cipher, plaintext, key, alphabet=al.ENGLISH): | ||
print('========================================================================================') | ||
print(plaintext) | ||
enc = cipher.encrypt(plaintext, key, alphabet) | ||
print(enc) | ||
print(cipher.decrypt(enc, key, alphabet)) | ||
|
||
|
||
plaintext = u"helloworld" | ||
key = "key" | ||
cipher = Beaufort() | ||
|
||
plaintext = u"thequickbrownfoxjumpsoverthelazydog" | ||
encdec(cipher, plaintext, key) | ||
|
||
alphabet = al.GERMAN | ||
plaintext = u"schweißgequältvomödentextzürnttypografjakob" | ||
encdec(cipher, plaintext, key, alphabet) | ||
|
||
alphabet = al.SWEDISH | ||
plaintext = u"faqomschweizklövdutrångpjäxby" | ||
encdec(cipher, plaintext, key, alphabet) | ||
|
||
cm = CryptMachine(Beaufort(), key) | ||
# using cryptmachine | ||
|
||
print(plaintext) | ||
enc = cm.encrypt(plaintext) | ||
print(enc) | ||
dec = cm.decrypt(enc) | ||
print(dec) | ||
|
||
print("-----------------------------------") | ||
def encdec(machine, plaintext): | ||
print("--------------------------------------------------------------------") | ||
print(plaintext) | ||
enc = machine.encrypt(plaintext) | ||
print(enc) | ||
print(machine.decrypt(enc)) | ||
|
||
alphabet = alphabets.GERMAN | ||
cm.set_alphabet(alphabet) | ||
|
||
print(plaintext) | ||
enc = cm.encrypt(plaintext) | ||
print(enc) | ||
dec = cm.decrypt(enc) | ||
print(dec) | ||
cm0 = CryptMachine(cipher, key) | ||
|
||
plaintext = "I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!" | ||
cm = SaveAll(cm0) | ||
encdec(cm, plaintext) | ||
|
||
cm.set_alphabet(al.ENGLISH_SQUARE_IJ) | ||
plaintext = "Jj becomes Ii because we use ENGLISH_SQUARE_IJ!" | ||
encdec(cm, plaintext) | ||
|
||
cm.set_alphabet(al.JAPANESE_HIRAGANA) | ||
cm.set_key(u"だやぎへ") | ||
plaintext = u"text あい だやぎへぐゆぢ" | ||
encdec(cm, plaintext) | ||
|
||
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!" | ||
cm = cm0 | ||
cm.set_alphabet(al.ENGLISH) | ||
cm.set_key(key) | ||
encdec(cm, plaintext) | ||
|
||
''' | ||
helloworld | ||
danzqcwnnh | ||
helloworld | ||
----------------------------------- | ||
helloworld | ||
danßucärnh | ||
helloworld | ||
Output: | ||
======================================================================================== | ||
thequickbrownfoxjumpsoverthelazydog | ||
rxuukqiuxtqcxzknveypgwjutlrgtylgvwy | ||
thequickbrownfoxjumpsoverthelazydog | ||
======================================================================================== | ||
schweißgequältvomödentextzürnttypografjakob | ||
wcrsaqlüuyoüßpdäwöhalvabvjäxvfvkjäühkßpkykj | ||
schweißgequältvomödentextzürnttypografjakob | ||
======================================================================================== | ||
faqomschweizklövdutrångpjäxby | ||
feizvgiåcgzöawzsbeuqäåäjbgbjj | ||
faqomschweizklövdutrångpjäxby | ||
-------------------------------------------------------------------- | ||
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it! | ||
C tkpa lwr-yzprkdur crknyilutm. Fdagg ehg : ^,&@$~(*;?&#. Lrkl'g cl! | ||
I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it! | ||
-------------------------------------------------------------------- | ||
Jj becomes Ii because we use ENGLISH_SQUARE_IJ! | ||
Bw xfclyag Bw xfcyqnu oa esa UXYOBNR_SPEKOU_BW! | ||
Ii becomes Ii because we use ENGLISH_SQUARE_II! | ||
-------------------------------------------------------------------- | ||
text あい だやぎへぐゆぢ | ||
text だも むもそすぇめぇ | ||
text あい だやぎへぐゆぢ | ||
-------------------------------------------------------------------- | ||
I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great! | ||
cbkxlnwjuxqlktjdexglwdehkcfgngciqzthgskpayztkflrgsstayr | ||
idontlovenonalphabetcharactersiwillremoveallofthemgreat | ||
''' |
Oops, something went wrong.