Пример #1
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)
Пример #2
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)
Пример #3
0
 def test_decryption_with_zero_key(self):
     Cipher = CaesarCipher(key=0)
     encrypted = Cipher.encrypt(self.sample_message)
     self.assertEqual(encrypted, self.sample_message)
Пример #4
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)
Пример #5
0
 def test_encryption_with_large_key(self):
     Cipher = CaesarCipher(key=26)
     result = Cipher.encrypt(self.sample_message)
     self.assertEqual(result, self.sample_message)
Пример #6
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)
Пример #7
0
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()
Пример #8
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)