Beispiel #1
0
def main():
    parser = argparse.ArgumentParser()
    group = parser.add_mutually_exclusive_group(required=True)
    group.add_argument("-e", "--encrypt", action="store_true")
    group.add_argument("-d", "--decrypt", action="store_true")
    parser.add_argument("-s", "--shift", type=int)
    parser.add_argument("input_file")
    parser.add_argument("output_file")
    args = parser.parse_args()

    cipher = CaesarCipher(args.shift)
    if args.encrypt:
        encrypt_file(args.input_file, args.output_file, cipher)
    elif args.decrypt:
        decrypt_file(args.input_file, args.output_file, cipher)
    else:
        pass
Beispiel #2
0
from caesar import CaesarCipher
from playfair import PlayFairCipher
from hill import HillCipher
from vigenere import VigenereCipher
from vernam import VernamCipher

# Caesar cipher algorithm takes input from caesar_plain.txt and output the cipher text to caesar_cipher.txt
# the CaesarCipher class constructor takes the plainText and the key
# Testing with key = 3 if you want to change the key, pass another key to the class constructor
caesarPlain = open('caesar_plain.txt', 'r').read().split('\n')
caesar = CaesarCipher(caesarPlain, 3)

# PlayfairCipher
playfairPlain = open('playfair_plain.txt', 'r').read().split('\n')
playfair = PlayFairCipher(playfairPlain, 'rats')

# HillCipher 2x2
hillPlain_2x2 = open('hill_plain_2x2.txt', 'r').read().split('\n')
hill_2x2 = HillCipher(hillPlain_2x2, [5, 17, 8, 3])

# HillCipher 3x3
hillPlain_3x3 = open('hill_plain_3x3.txt', 'r').read().split('\n')
hill_3x3 = HillCipher(hillPlain_3x3, [2, 4, 12, 9, 1, 6, 7, 5, 3])

# VigenereCipher auto mode
vigenereAutoPlain = open('vigenere_plain.txt', 'r').read().split('\n')
vigenereAuto = VigenereCipher(vigenereAutoPlain, 'aether', 1)

# VigenereCipher repeating mode
vigenereRepeatingPlain = open('vigenere_plain.txt', 'r').read().split('\n')
vigenereRepeating = VigenereCipher(vigenereRepeatingPlain, 'pie', 0)
Beispiel #3
0
 def test_encryption_with_key_a(self):
     Cipher = CaesarCipher(key=2)
     result = Cipher.encrypt(self.sample_message)
     expected = 'vjg swkem dtqyp hqz lworu qxgt vjg ncba fqi'
     self.assertEqual(result, expected)
Beispiel #4
0
 def test_decryption_with_zero_key(self):
     Cipher = CaesarCipher(key=0)
     encrypted = Cipher.encrypt(self.sample_message)
     self.assertEqual(encrypted, self.sample_message)
Beispiel #5
0
 def test_decryption_with_key_b(self):
     Cipher = CaesarCipher(key=20)
     encrypted = Cipher.encrypt(self.sample_message)
     decrypted = Cipher.decrypt(encrypted)
     self.assertEqual(decrypted, self.sample_message)
Beispiel #6
0
 def test_encryption_with_uppercase_message(self):
     Cipher = CaesarCipher(key=10)
     result = Cipher.encrypt(self.sample_message.upper())
     expected = 'dro aesmu lbygx pyh tewzc yfob dro vkji nyq'
     self.assertEqual(result, expected)
Beispiel #7
0
 def test_encryption_with_large_key(self):
     Cipher = CaesarCipher(key=26)
     result = Cipher.encrypt(self.sample_message)
     self.assertEqual(result, self.sample_message)
Beispiel #8
0
 def test_encryption_with_key_b(self):
     Cipher = CaesarCipher(key=20)
     result = Cipher.encrypt(self.sample_message)
     expected = 'nby kocwe vliqh zir dogjm ipyl nby futs xia'
     self.assertEqual(result, expected)
def main():
    args = str(sys.argv)
    cipher = sys.argv[1].lower()
    key = sys.argv[2]
    mode = sys.argv[3].upper()
    input_file = sys.argv[4]
    output_file = sys.argv[5]

    if mode == "ENC":
        if cipher == 'vig':
            vig = Vigenre()
            if (vig.setKey(key)):
                vig.encrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'ces':
            ces = CaesarCipher()
            if (ces.setKey(key)):
                ces.encrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'rts':
            rts = RowTransposition()
            if (rts.setKey(key)):
                rts.encrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'rfc':
            rfc = RailfenceCipher()
            if (rfc.setKey(key)):
                rfc.encrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'plf':
            plf = Play()
            if (plf.setKey(key)):
                plf.encrypt(input_file, output_file)
            else:
                print "Key Error"

    elif mode == "DEC":
        if cipher == 'vig':
            vig = Vigenre()
            if (vig.setKey(key)):
                vig.decrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'ces':
            ces = CaesarCipher()
            if (ces.setKey(key)):
                ces.decrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'rts':
            rts = RowTransposition()
            if (rts.setKey(key)):
                rts.decrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'rfc':
            rfc = RailfenceCipher()
            if (rfc.setKey(key)):
                rfc.decrypt(input_file, output_file)
            else:
                print "Key Error"

        elif cipher == 'plf':
            plf = Play()
            if (plf.setKey(key)):
                plf.decrypt(input_file, output_file)
            else:
                print "Key Error"

    else:
        print "Invalid mode: use DEC/ENC"

    exit()
Beispiel #10
0
from caesar import CaesarCipher

if __name__ == "__main__":
    key = int(input("Enter a key (0-25): "))
    message = input("Enter a message: ")
    message = message.lower()

    Cipher = CaesarCipher(key)
    encrypted = Cipher.encrypt(message)
    decrypted = Cipher.decrypt(encrypted)

    print("Encrypted: {}".format(encrypted))
    print("Decrypted: {}".format(decrypted))

    Cipher.bruteforce(encrypted)