Example #1
0
    def setUp(self):
        self.text1 = 'testing message'
        self.text2 = 'A m4ssage with punctuation in it+... Fun!'
        self.text3 = 'zzzzz~~~~....'
        self.text4 = 'he,(llo)'

        self.msg1 = student.Message(self.text1)
        self.msg2 = student.Message(self.text2)
        self.msg3 = student.Message(self.text3)
        self.msg4 = student.Message(self.text4)

        self.pads = [[71, 12, 44, 87, 81, 30, 61, 5, 66, 19, 73, 91, 19, 8, 83],
                     [34, 92, 62, 59, 32, 91, 21, 81, 94, 37, 20, 76, 17, 20, 7, 30, 3, 28, 21, 14, 67, 9, 91, 49, 4, 87, 25, 12, 88, 68, 37, 18, 62, 30, 79, 82, 83, 71, 7, 86, 77],
                     [73, 72, 17, 48, 0, 0, 34, 40, 45, 87, 25, 48, 16],
                     [47, 45, 29, 87, 44, 8, 87, 61]]
        self.ptmsg1 = student.PlaintextMessage(self.text1, self.pads[0])
        self.ptmsg2 = student.PlaintextMessage(self.text2, self.pads[1])
        self.ptmsg3 = student.PlaintextMessage(self.text3, self.pads[2])
        self.ptmsg4 = student.PlaintextMessage(self.text4, self.pads[3])
Example #2
0
    def setUp(self):
        self.text1 = 'testing message'
        self.text2 = 'A message with punctuation in it... Fun!'
        self.text3 = 'zzzzz....'

        self.encrypt1 = 'wgvvlpj pgvudih'
        self.encrypt2 = 'B nhtvbjf xluk svqdwvdulpq lo jw... Gxo!'
        self.encrypt3 = 'azaza....'

        # do this so "loading words" doesn't print out every time
        with redirect_stdout(open(os.devnull, "w")):
            self.msg1 = student.Message(self.text1)
            self.msg2 = student.Message(self.text2)
            self.msg3 = student.Message(self.text3)

            self.ptmsg1 = student.PlaintextMessage(self.text1, [3, 2])  #1
            self.ptmsg2 = student.PlaintextMessage(self.text2, [1, 3])  #2
            self.ptmsg3 = student.PlaintextMessage(self.text3, [1, 0])

            self.ctmsg1 = student.EncryptedMessage(self.encrypt1)
            self.ctmsg2 = student.EncryptedMessage(self.encrypt2)
            self.ctmsg3 = student.EncryptedMessage(self.encrypt3)
Example #3
0
 def test_plaintext_message_encrypted_msg(self):
     pds = [(self.ptmsg1, '\\q@l[-E%Px]otoY', [63, 34, 46, 81, 31, 88, 60, 42, 10, 68, 40, 28, 86, 71, 10], 'T(Bf)gDJwJ<0XOo'),
             (self.ptmsg2, "c|Lo4ovYdE,V&|'/x+x#Yjp;sf9ugd/'iL}!s.|en", [19, 44, 12, 44, 40, 28, 24, 8, 42, 77, 77, 54, 81, 11, 8, 88, 77, 42, 88, 82, 55, 0, 29, 43, 34, 55, 89, 13, 25, 56, 34, 88, 74, 58, 16, 34, 79, 26, 68, 74, 15], "TLy`<0yo0me@fs(ic9\\gMa252Fyv(X,muh>Po`ZY0"),
             (self.ptmsg3, 'dc,Kz~AGL&G^>', [52, 87, 79, 89, 15, 80, 69, 63, 54, 66, 68, 86, 16], 'Orjt*od^Upr%>'),
             (self.ptmsg4, '83I 9tgf', [63, 73, 66, 38, 11, 47, 66, 19], 'HOnNw<R<')]
     for p, init_enc, new_pad, new_enc in pds:
         result = p.get_encrypted_message_text()
         self.assertEqual(init_enc, result, "The encrypted message returned was {} but {} was expected".format(result, init_enc))
         p.change_pad(new_pad)
         result = p.get_encrypted_message_text()
         self.assertNotEqual(init_enc, result, "change_pad did not update the encrypted message")
         self.assertEqual(new_enc, result, "The encrypted message returned was {} but {} was expected".format(result, new_enc))
     random.seed(0)
     new_plaintext = student.PlaintextMessage('Testing generating pad!')
     result = new_plaintext.get_encrypted_message_text()
     exp = '&;x6KM;FE3Y!Sr9zzW@U\\R3'
     self.assertEqual(exp, result, "The PlaintextMessage encrypted message from a randomly generated pad was {} but {} was expected".format(result, exp))
Example #4
0
    def test_plaintext_message_pad(self):
        pds = [(self.ptmsg1, self.pads[0], [63, 34, 46, 81, 31, 88, 60, 42, 10, 68, 40, 28, 86, 71, 10]),
                (self.ptmsg2, self.pads[1], [19, 44, 12, 44, 40, 28, 24, 8, 42, 77, 77, 54, 81, 11, 8, 88, 77, 42, 88, 82, 55, 0, 29, 43, 34, 55, 89, 13, 25, 56, 34, 88, 74, 58, 16, 34, 79, 26, 68, 74, 15]),
                (self.ptmsg3, self.pads[2], [52, 87, 79, 89, 15, 80, 69, 63, 54, 66, 68, 86, 16]),
                (self.ptmsg4, self.pads[3], [63, 73, 66, 38, 11, 47, 66, 19])]
        for p, init_pad, set_pad in pds:
            result=p.get_pad()
            self.assertEqual(init_pad, result, "The PlaintextMessage was initialized with the pad {} but get_pad() returned {}".format(init_pad, result))
            p.change_pad(set_pad)
            result=p.get_pad()
            self.assertEqual(set_pad, result, "The PlaintextMessage pad was changed to {} but get_pad() returned {}".format(set_pad, result))

        random.seed(0)
        new_plaintext = student.PlaintextMessage('Testing generating pad!')
        result = new_plaintext.get_pad()
        exp = [49, 53, 5, 33, 65, 62, 51, 38, 61, 45, 74, 27, 64, 17, 36, 17, 12, 79, 32, 68, 90, 77, 18]
        self.assertEqual(exp, result, "The randomly generated PlaintextMessage pad was {} but {} was expected".format(result, exp))
Example #5
0
    def setUp(self):
        self.text1 = 'testing message'
        self.text2 = 'A message with punctuation in it... Fun!'
        self.text3 = 'zzzzz....'
        self.text4 = 'he,llo'
        self.text5 = 'My PIN is 12345 so secure!'
        self.text6 = 'H3LL0 W0RLD'

        self.encrypt1 = 'whvwlqj phvvdjh'
        self.encrypt2 = 'B nfttbhf xjui qvoduvbujpo jo ju... Gvo!'
        self.encrypt3 = 'bbbbb....'
        self.encrypt4 = 'he,llo'
        self.encrypt5 = 'Xj ATY td 23456 dz dpnfcp!'
        self.encrypt6 = 'K6OO3 Z3UOG'

        # do this so "loading words" doesn't print out every time
        with redirect_stdout(open(os.devnull, "w")):
            self.msg1 = student.Message(self.text1)
            self.msg2 = student.Message(self.text2)
            self.msg3 = student.Message(self.text3)
            self.msg4 = student.Message(self.text4)
            self.msg5 = student.Message(self.text5)
            self.msg6 = student.Message(self.text6)

            self.ptmsg1 = student.PlaintextMessage(self.text1, 3) #1
            self.ptmsg2 = student.PlaintextMessage(self.text2, 1) #2
            self.ptmsg3 = student.PlaintextMessage(self.text3, 2)
            self.ptmsg4 = student.PlaintextMessage(self.text4, 0)
            self.ptmsg5 = student.PlaintextMessage(self.text5, 11)
            self.ptmsg6 = student.PlaintextMessage(self.text6, 3)

            self.ctmsg1 = student.EncryptedMessage(self.encrypt1)
            self.ctmsg2 = student.EncryptedMessage(self.encrypt2)
            self.ctmsg3 = student.EncryptedMessage(self.encrypt3)
            self.ctmsg4 = student.EncryptedMessage(self.encrypt4)
            self.ctmsg5 = student.EncryptedMessage(self.encrypt5)
            self.ctmsg6 = student.EncryptedMessage(self.encrypt6)
Example #6
0
 def test_plaintext(self):
     self.assertEqual(ps4b.PlaintextMessage('hello', 2).get_message_text_encrypted(), "jgnnq")
     self.assertEqual(ps4b.PlaintextMessage('Great!', 4).get_message_text_encrypted(), 'Kviex!')
import ps4b as ps

sentence = "Hello*, is this! me?"

message = ps.Message(sentence)

#print(message.get_message_text())
#print(message.get_valid_words())
#print(message.build_shift_dict(shift = 2))

message2 = ps.PlaintextMessage(sentence, 3)
#print(message2.get_valid_words())

#print(message2.get_message_text_encrypted())

cipher = ps.CiphertextMessage(message2.get_message_text_encrypted())
#print("is it working?")
#print(cipher.decrypt_message())

ciph_msg = ps.CiphertextMessage("ifmmp")

plain_msg = ps.PlaintextMessage("Hello", 1)

print("we're applying the shift code")

plain_cipher = plain_msg.apply_shift(1)
print(plain_msg.get_message_text())
print(plain_msg.get_message_text_encrypted())

print("we're deciphering the message")