Ejemplo n.º 1
0
def atbashCipher():
    mode = getMode()
    message = getMessage()
    cm = CryptMachine(Atbash())
    cm = md.NoSpaces(md.UpperCase(cm))
    print('\nYour translated text is:')
    if mode == 'e' or mode == 'encrypt':
        out = cm.encrypt(message)
        print(out)
    else:
        out = cm.decrypt(message)
        print(out)
    return out
Ejemplo n.º 2
0
def trifidCipher():
    mode = getMode()
    message = getMessage()
    key = getKey()
    machine = CryptMachine(Trifid(), key)
    print('\nYour translated text is:')
    if mode == 'e' or mode == 'encrypt':
        out = machine.encrypt(message)
        print(out)
    else:
        out = machine.decrypt(message)
        print(out)
    return out
Ejemplo n.º 3
0
def Decryp_Affine_t(arg1,arg2,arg3):
    data = arg1
    key1 = int(arg2)
    key2 = int(arg3)
    key=[key1,key2]
    cm = SaveSpaces(SaveCase(CryptMachine(Affine(),key)))
    return(cm.decrypt(data))
Ejemplo n.º 4
0
def Decryp_Affine():
    data = input("Enter dtata to be Decrypted By Affine Algorithm : ")
    key1 = int(input("Enter key1 : "))
    key2 = int(input("Enter key2 : "))
    key=[key1,key2]
    cm = SaveSpaces(SaveCase(CryptMachine(Affine(),key)))
    print(cm.decrypt(data))
    input("Copy if needed.............")
Ejemplo n.º 5
0
    def test_main(self, Atbash, Caesar):
        cipher1 = Caesar()
        cipher1.encrypt.return_value = "caesarencrypted"
        cipher1.decrypt.return_value = "caesardecrypted"

        cipher2 = Atbash()
        cipher2.encrypt.return_value = "atbashencrypted"
        cipher2.decrypt.return_value = "atbashdecrypted"

        cm1 = CryptMachine(Caesar(), 3)
        cm2 = CryptMachine(Atbash())
        cm = CompositeMachine(cm1, cm2)
        enc = cm.encrypt("text")
        dec = cm.decrypt(enc)

        self.assertEqual(enc, "atbashencrypted")
        self.assertEqual(dec, "atbashdecrypted")
Ejemplo n.º 6
0
    def test_main(self, Atbash, Caesar):
        cipher1 = Caesar()
        cipher1.encrypt.return_value = "CAESAR_ENCRYPTED"
        cipher1.decrypt.return_value = "CAESAR_DECRYPTED"

        cipher2 = Atbash()
        cipher2.encrypt.return_value = "ATBASH_ENCRYPTED"
        cipher2.decrypt.return_value = "ATBASH_DECRYPTED"

        cm1 = CryptMachine(Caesar(), 3)
        cm2 = CryptMachine(Atbash())
        cm = CompositeMachine(cm1, cm2)
        enc = cm.encrypt("text")
        dec = cm.decrypt(enc)

        self.assertEqual(enc, "ATBASH_ENCRYPTED")
        self.assertEqual(dec, "ATBASH_DECRYPTED")

        cipher2.encrypt.assert_called_with(
            "CAESAR_ENCRYPTED", "", u"abcdefghijklmnopqrstuvwxyz")
        cipher2.decrypt.assert_called_with(
            "CAESAR_DECRYPTED", "", u"abcdefghijklmnopqrstuvwxyz")
Ejemplo n.º 7
0
def main():

    # parse out each verse
    with open("ramblings", "r") as fd:
        keystrings = fd.readlines()

    # filter and cleanup into a 25-char key
    keys = []
    for key in keystrings:
        key = key.lower()
        for rm in REMOVE:
            key = key.replace(rm, "")

        # helps us catch characters we don't want
        if len(key) != 25:
            continue
        keys += [key]

    # take each cleaned up key and encrypt using Bifid cipher
    key = 5
    cm = CryptMachine(Bifid(), key)

    plaintext = u"just some unnecessary text that holds absolutely no meaning whatsoever and bears no significance to you in any way"
    ciphertext = plaintext

    # encrypt plaintext
    for key in keys:
        alphabet = [u'{}'.format(i) for i in list(key)]
        cm.set_alphabet(alphabet)
        ciphertext = cm.encrypt(ciphertext)

    print("Ciphertext generated: {}".format(ciphertext))

    # decrypt plaintext
    final_plaintext = ciphertext
    for key in reversed(keys):
        alphabet = [u'{}'.format(i) for i in list(key)]
        cm.set_alphabet(alphabet)
        final_plaintext = cm.decrypt(final_plaintext)

    print("Final Plaintext recovered: {}".format(final_plaintext))
Ejemplo n.º 8
0
# -*- encoding: utf-8 -*-

from secretpy import Rot13, CryptMachine, alphabets as al
from secretpy.cmdecorators import SaveAll, Block


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = CryptMachine(Rot13())

plaintext = u"The quick brown fox jumps over the lazydog."
encdec(cm, plaintext)

cm = SaveAll(cm)

plaintext = u"Why did the chicken cross the road? Gb trg gb gur bgure fvqr"
encdec(cm, plaintext)

plaintext = u"Die heiße Zypernsonne quälte Max und Victoria ja böse auf dem Weg bis zur Küste."
cm.set_alphabet(al.GERMAN)
encdec(cm, plaintext)

plaintext = u"FAQ om Schweiz: Klöv du trång pjäxby?"
cm.set_alphabet(al.SWEDISH)
Ejemplo n.º 9
0
# -*- encoding: utf-8 -*-

from secretpy import Nihilist
from secretpy import CryptMachine


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = "russian"
cm = CryptMachine(Nihilist(), key)
alphabet = [
    u"z", u"e", u"b", u"r", u"a", u"s", u"c", u"d", u"f", u"g", u"h", u"ij",
    u"k", u"l", u"m", u"n", u"o", u"p", u"q", u"t", u"u", u"v", u"w", u"x",
    u"y"
]
plaintext = u"dynamitewinterpalace"
cm.set_alphabet(alphabet)
encdec(cm, plaintext)

alphabet = [
    u"a",
    u"b",
    u"c",
    u"d",
    u"e",
Ejemplo n.º 10
0
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import MyszkowskiTransposition, CryptMachine
from secretpy import alphabets


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("-------------------------------")


key = "tomato"
cm = CryptMachine(MyszkowskiTransposition(), key)

alphabet = alphabets.ENGLISH

cm.set_alphabet(alphabet)
plaintext = "wearediscoveredfleeatonce"
encdec(cm, plaintext)

'''
wearediscoveredfleeatonce
rofoacdtedseeeacweivrlene
wearediscoveredfleeatonce
-------------------------------
'''
Ejemplo n.º 11
0
from secretpy import Atbash
from secretpy import CryptMachine
from secretpy import alphabets
import secretpy.cmdecorators as md


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


cm = CryptMachine(Atbash())
cm = md.NoSpaces(md.UpperCase(cm))

plaintext = u"attackatdawn"
encdec(cm, plaintext)

plaintext = u"במקום"
cm.set_alphabet(alphabets.HEBREW)
encdec(cm, plaintext)

plaintext = u"The Fox jumps in Zoo too Achtung minen"
cm.set_alphabet(alphabets.GERMAN)
encdec(cm, plaintext)

plaintext = u"Achtung Minen"
encdec(cm, plaintext)
Ejemplo n.º 12
0
# -*- encoding: utf-8 -*-

from secretpy import ADFGVX, CryptMachine
from secretpy.cmdecorators import Block, UpperCase


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("-------------------------------")


key = "privacy"
cm = UpperCase(Block(CryptMachine(ADFGVX(), key), 4))

alphabet = (
    u"n", u"a", u"1", u"c", u"3", u"h",
    u"8", u"t", u"b", u"2", u"o", u"m",
    u"e", u"5", u"w", u"r", u"p", u"d",
    u"4", u"f", u"6", u"g", u"7", u"i",
    u"9", u"j", u"0", u"k", u"l", u"q",
    u"s", u"u", u"v", u"x", u"y", u"z",
)
cm.set_alphabet(alphabet)
plaintext = "Attack at 12.00am!"
encdec(cm, plaintext)

key = "pangram"
cm.set_key(key)
Ejemplo n.º 13
0
# -*- encoding: utf-8 -*-

from secretpy import Vic
from secretpy import CryptMachine


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = "0452"
cm = CryptMachine(Vic(), key)
alphabet = [
    u"e",
    u"t",
    u"",
    u"a",
    u"o",
    u"n",
    u"",
    u"r",
    u"i",
    u"s",
    u"b",
    u"c",
    u"d",
    u"f",
Ejemplo n.º 14
0
print(plaintext)
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    print("=" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)

cm = cm0
cm = UpperCase(Block(cm0))
key = 5
cm.set_key(key)
cm.set_alphabet(al.ENGLISH)
plaintext = "WE ARE DISCOVERED FLEE AT ONCE"
encdec(cm, plaintext)

cm = cm0
cm.set_alphabet(al.ENGLISH)
plaintext = "I don't love non-alphabet characters and uppercase. I will remove all of them: ^,&@$~(*;?&#."
encdec(cm, plaintext)

cm = Block(cm, length=5, sep=" ")
Ejemplo n.º 15
0
from secretpy import Playfair
from secretpy import CryptMachine
from secretpy.cmdecorators import NoSpaces, UpperCase


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


cm = NoSpaces(UpperCase(CryptMachine(Playfair())))
alphabet = [
    u"p",
    u"l",
    u"a",
    u"y",
    u"f",
    u"i",
    u"r",
    u"e",
    u"x",
    u"m",
    u"b",
    u"c",
    u"d",
    u"g",
Ejemplo n.º 16
0
# -*- encoding: utf-8 -*-

from secretpy import Bifid
from secretpy import CryptMachine


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = 5
cm = CryptMachine(Bifid(), key)
alphabet = [
    u"а", u"б", u"в", u"г", u"д", u"её", u"ж", u"з", u"ий", u"к", u"л", u"м",
    u"н", u"о", u"п", u"р", u"с", u"т", u"у", u"ф", u"х", u"ц", u"ч", u"ш",
    u"щ", u"ы", u"ьъ", u"э", u"ю", u"я", u"1", u"2", u"3", u"4", u"5", u"6"
]

cm.set_alphabet(alphabet)
plaintext = u"текст"
encdec(cm, plaintext)

alphabet = [
    u"p", u"h", u"q", u"g", u"m", u"e", u"a", u"y", u"l", u"n", u"o", u"f",
    u"d", u"x", u"k", u"r", u"c", u"v", u"s", u"z", u"w", u"b", u"u", u"t",
    u"ij"
]
Ejemplo n.º 17
0
# -*- encoding: utf-8 -*-

from secretpy import Bazeries, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, SaveAll


def encdec(machine, plaintext):
    print("=" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = UpperCase(CryptMachine(Bazeries()))
cm.set_alphabet(al.ENGLISH_SQUARE_IJ)

key = (81257, u"eightyonethousandtwohundredfiftyseven")
cm.set_key(key)
plaintext = u"Whoever has made a voyage up the Hudson" \
            u" must remember the Kaatskill mountains"
encdec(cm, plaintext)

cm = SaveAll(cm)
encdec(cm, plaintext)

cm = UpperCase(SaveAll(CryptMachine(Bazeries(), key)))
cm.set_alphabet(al.ENGLISH_SQUARE_IJ)
plaintext = u"The quick brown fox jumps over the lazy dog!"
encdec(cm, plaintext)
Ejemplo n.º 18
0
from secretpy import ThreeSquare, CryptMachine, alphabets as al
from secretpy.cmdecorators import UpperCase, SaveAll, Block


def encdec(machine, plaintext):
    print("=" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


key = (u"example", u"keyword", u"third")
cm = UpperCase(CryptMachine(ThreeSquare()))
cm.set_alphabet(al.ENGLISH_SQUARE_OQ)
cm.set_key(key)
plaintext = u"The quick brown fox jumps over the lazy dog!"
encdec(cm, plaintext)

cm = SaveAll(cm)
encdec(cm, plaintext)

cm = SaveAll(CryptMachine(ThreeSquare()))
cm.set_alphabet(al.ENGLISH_SQUARE_IJ)
key = (u"criptog", u"segurt", u"mars")
cm.set_key(key)
plaintext = u"Attack at dawns!!!"
encdec(cm, plaintext)
Ejemplo n.º 19
0

def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


alphabet = alphabets.ENGLISH_SQUARE_OQ

key = (u"example", u"keyword")

cm = UpperCase(CryptMachine(TwoSquare()))

cm.set_alphabet(alphabet)
cm.set_key(key)
plaintext = u"Help me Obi wan Kenobi"
encdec(cm, plaintext)

plaintext = u"Help me Obi wan Kenobi y"
encdec(cm, plaintext)
'''
Help me Obi wan Kenobi
XGDLXWSDJYRYHOTKDG
HELPMEOBIWANKENOBI
----------------------------------
Help me Obi wan Kenobi y
XGDLXWSDJYRYHOTKDGZX
Ejemplo n.º 20
0
# -*- encoding: utf-8 -*-

from secretpy import Atbash, CryptMachine, alphabets
from secretpy.cmdecorators import UpperCase, SaveAll


def encdec(machine, plaintext):
    print("-" * 80)
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = UpperCase(CryptMachine(Atbash()))

plaintext = u"attackatdawn"
encdec(cm, plaintext)

plaintext = u"במקום"
cm.set_alphabet(alphabets.HEBREW)
encdec(cm, plaintext)

cm = SaveAll(cm)
plaintext = u"The quick brown fox jumps over the lazy dog."
cm.set_alphabet(alphabets.GERMAN)
encdec(cm, plaintext)

plaintext = u"Achtung Minen!!!"
encdec(cm, plaintext)
Ejemplo n.º 21
0

def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("-----------------------------------")


plaintext = u"thequickbrownfoxjumpsoverthelazydog"
key = 3
cipher = Caesar()

cm = CryptMachine(cipher, key)
encdec(cm, plaintext)

cm.set_alphabet(alphabets.GERMAN)
encdec(cm, plaintext)

cm1 = SaveAll(cm)
cm1.set_key(9)
plaintext = u"the quick brown fox jumps over the lazy dog"
encdec(cm1, plaintext)

cm2 = cm
cm2.set_cipher(Atbash())
plaintext = u"Achtung Minen"
encdec(cm2, plaintext)
Ejemplo n.º 22
0
from secretpy import Rot18
from secretpy import CryptMachine
from secretpy.cmdecorators import SaveCase, SaveSpaces, UpperCase
from secretpy import alphabets


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = SaveCase(SaveSpaces(CryptMachine(Rot18())))

plaintext = u"The man has 536 dogs"
encdec(cm, plaintext)

plaintext = alphabets.RUSSIAN + alphabets.DECIMAL
cm.set_alphabet(alphabets.RUSSIAN)
encdec(cm, plaintext)

plaintext = u"У человека 536 собак"
encdec(cm, plaintext)

plaintext = alphabets.GREEK + " " + alphabets.DECIMAL
cm = UpperCase(cm)
cm.set_alphabet(alphabets.GREEK)
encdec(cm, plaintext)
Ejemplo n.º 23
0
enc = cipher.encrypt(plaintext, key, alphabet)
print(enc)
dec = cipher.decrypt(enc, key, alphabet)
print(dec)


def encdec(machine, plaintext):
    print(
        "--------------------------------------------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))


cm0 = CryptMachine(cipher, key)
cm0.set_alphabet(al.ENGLISH + al.DECIMAL)

cm = cm0
plaintext = "I don't love non-alphabet characters. I will remove all of them: ^,&@$~(*;?&#. Great!"
encdec(cm, plaintext)

cm = UpperCase(Block(cm, length=5, sep="-"))
plaintext = "This text is divided by blocks of length 5!"
encdec(cm, plaintext)

cm = SaveAll(cm0)
plaintext = "I love non-alphabet characters. These are : ^,&@$~(*;?&#. That's it!"
encdec(cm, plaintext)

cm.set_alphabet(al.JAPANESE_HIRAGANA)
Ejemplo n.º 24
0

def encdec(machine, plaintext):
    print("=======================================")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


key = 5
plaintext = u"Dog jumps four times and cat six times"
print(plaintext)

cm1 = SaveAll(CryptMachine(Caesar(), key))
enc = cm1.encrypt(plaintext)
print(enc)

cm2 = SaveAll(CryptMachine(Rot13()))
enc = cm2.encrypt(enc)
print(enc)

print("=======================================")

cm = CompositeMachine(cm1)
cm.add_machines(cm2)
enc = cm.encrypt(plaintext)
print(enc)
encdec(cm, plaintext)
Ejemplo n.º 25
0
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import CryptMachine
from secretpy import Beaufort
from secretpy import alphabets

plaintext = u"helloworld"
key = "key"

cm = CryptMachine(Beaufort(), key)

print(plaintext)
enc = cm.encrypt(plaintext)
print(enc)
dec = cm.decrypt(enc)
print(dec)

print("-----------------------------------")

alphabet = alphabets.GERMAN
cm.set_alphabet(alphabet)

print(plaintext)
enc = cm.encrypt(plaintext)
print(enc)
dec = cm.decrypt(enc)
print(dec)
'''
helloworld
danzqcwnnh
Ejemplo n.º 26
0
from secretpy import Rot18, CryptMachine
from secretpy.cmdecorators import SaveAll, UpperCase, Block


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


plaintext = u"The man has 536 dogs! How many dogs do you have?"

cm = CryptMachine(Rot18())
encdec(cm, plaintext)

cm1 = Block(cm)
encdec(cm1, plaintext)

cm = SaveAll(cm)
encdec(cm, plaintext)

cm = UpperCase(cm)
encdec(cm, plaintext)
'''
----------------------------------
The man has 536 dogs! How many dogs do you have?
gurznaunf081qbtfubjznalqbtfqblbhunir
themanhas536dogshowmanydogsdoyouhave
Ejemplo n.º 27
0
from secretpy import Polybius
from secretpy import CryptMachine
from secretpy.cmdecorators import LowerCase
import secretpy.alphabet as alph


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


cm = CryptMachine(Polybius())

plaintext = u"defendtheeastwallofthecastle"
encdec(cm, plaintext)

alphabet = [
    u"p", u"h", u"q", u"g", u"m",
    u"e", u"a", u"y", u"l", u"n",
    u"o", u"f", u"d", u"x", u"k",
    u"r", u"c", u"v", u"s", u"z",
    u"w", u"b", u"u", u"t", u"ij"
]
cm.set_alphabet(alphabet)
plaintext = "sometext"
encdec(cm, plaintext)
Ejemplo n.º 28
0
# -*- encoding: utf-8 -*-

from secretpy import Trifid
from secretpy import CryptMachine


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    print(machine.decrypt(enc))
    print("----------------------------------")


key = 5
cm = CryptMachine(Trifid(), key)

alphabet = [
    u"e",
    u"p",
    u"s",
    u"d",
    u"u",
    u"c",
    u"v",
    u"w",
    u"y",
    u"m",
    u".",
    u"z",
    u"l",
Ejemplo n.º 29
0
#!/usr/bin/python
# -*- encoding: utf-8 -*-

from secretpy import Rot5, alphabets, CryptMachine


def encdec(machine, plaintext):
    print("----------------------------------")
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)


cm = CryptMachine(Rot5())

plaintext = "My text " + alphabets.DECIMAL + " your text"
encdec(cm, plaintext)

'''
----------------------------------
My text 0123456789 your text
5678901234
0123456789
'''
Ejemplo n.º 30
0
from secretpy import alphabets
from secretpy.cmdecorators import NoSpaces, UpperCase


def encdec(machine, plaintext):
    print(plaintext)
    enc = machine.encrypt(plaintext)
    print(enc)
    dec = machine.decrypt(enc)
    print(dec)
    print("----------------------------------")


alphabet = alphabets.ENGLISH_SQUARE_IJ

key = (81257, u"eightyonethousandtwohundredfiftyseven")

cm = NoSpaces(UpperCase(CryptMachine(Bazeries())))

cm.set_alphabet(alphabet)
cm.set_key(key)
plaintext = u"Whoever has made a voyage up the Hudson" \
            u" must remember the Kaatskill mountains"
encdec(cm, plaintext)
'''
Whoever has made a voyage up the Hudson must remember the Kaatskill mountains
DUMTMCDSENRTEMVEQXMOELCCRVXDMDKWXNNMUKRDKUMYNMBPRKEEPMGNGEKWXCRWB
WHOEVERHASMADEAVOYAGEUPTHEHUDSONMUSTREMEMBERTHEKAATSKILLMOUNTAINS
----------------------------------
'''