예제 #1
0
class CaesarCipher(object):
    def __init__(self, key=3):
        self.key = key
        self.letters = list(string.ascii_lowercase)  # a to z
        self.helper = CodeHelper()

    def encrypt(self, msg):
        code = self.helper.to_code(msg)
        encrypted = []
        for i in code:
            index = i + self.key
            if index >= len(self.letters):
                index = index % len(self.letters)
            encrypted.append(index)
        encrypted = self.helper.to_str(encrypted)
        return encrypted

    def decrypt(self, msg):
        decrypted = []
        for i in msg:
            index = self.letters.index(i) - self.key
            decrypted.append(index)
        decrypted = self.helper.to_str(decrypted)
        return decrypted
예제 #2
0
class CaesarCipher(object):
    def __init__(self, key=3):
        self.key = key
        self.letters = list(string.ascii_lowercase) # a to z
        self.helper = CodeHelper()

    def encrypt(self, msg):
        code = self.helper.to_code(msg)
        encrypted = []
        for i in code:
            index = i + self.key
            if index >= len(self.letters):
                index = index % len(self.letters)
            encrypted.append(index)
        encrypted = self.helper.to_str(encrypted)
        return encrypted

    def decrypt(self, msg):
        decrypted = []
        for i in msg:
            index = self.letters.index(i) - self.key
            decrypted.append(index)
        decrypted = self.helper.to_str(decrypted)
        return decrypted
예제 #3
0
 def __init__(self, key=3):
     self.key = key
     self.letters = list(string.ascii_lowercase)  # a to z
     self.helper = CodeHelper()
예제 #4
0
 def __init__(self, key=3):
     self.key = key
     self.letters = list(string.ascii_lowercase) # a to z
     self.helper = CodeHelper()
예제 #5
0
 def setUp(self):
     self.code_helper = CodeHelper()
예제 #6
0
class CodeHelperTestCase(unittest.TestCase):
    def setUp(self):
        self.code_helper = CodeHelper()

    def test_should_get_2_17_8_15_19_14_6_17_0_5_8_0_code_to_criptografia_word(self):
        assert_equals(self.code_helper.to_code("criptografia"), [2,17,8,15,19,14,6,17,0,5,8,0])