Esempio n. 1
0
def alien_view(username):
    # Calculate shift
    shift = shift_map(username)

    # Calculate JAR url
    jar_name = file_for_u(username)
    jar_url = "/suchsecret/{jar}".format(jar=jar_name)
    jar_url_enc = cipher(jar_url, shift)

    # Pass it through jinja
    html_doc_rendered = render_template_string(html_doc,
                                               jar_url_enc=jar_url_enc,
                                               jar_url=jar_url)

    # Init parser
    soup = BeautifulSoup(html_doc_rendered, 'lxml')

    # Iterate through every element and replace the inner text with cipher
    for element in soup.findAll():
        for index, sub_element in enumerate(element.contents):
            if type(sub_element) == NavigableString:
                element.contents[index].replace_with(
                    cipher(element.contents[index].strip(), shift))

    # Render it in browser
    return soup.prettify(formatter=None)
Esempio n. 2
0
def encrypt(inputFile, outputFile, keySize, keyFile, keyLength, num_rounds):
    keySchedule = keyExpansion(keyFile, keyLength, num_rounds)

    # numBytes = numBits // 8
    # read file as binary
    in_file = open(inputFile, 'rb')
    out_file = open(outputFile, 'wb')

    # try catch surrounding, lots of testing

    file_bytes = in_file.read()
    padding_length = 16 - len(file_bytes) % 16
    file_bytes += bytes([padding_length] * padding_length)

    # sanity check
    assert (len(file_bytes) % 16 == 0)

    for i in range(len(file_bytes) // 16):
        state = []
        chunk = file_bytes[i * 16:(i + 1) * 16]
        for row in range(4):
            state.append([])
            for column in range(4):
                state[row].append(chunk[row * 4 + column])

        output = cipher(state, keySchedule, num_rounds)
        output_bytes = bytearray()
        for t in range(4):
            output_bytes.extend(bytes(output[t]))

        bytes_written = out_file.write(output_bytes)
        # sanity check
        assert (bytes_written == 16)
    out_file.close()
Esempio n. 3
0
def main():
    print("\n#===== Transposição =====#")

    key = input("Digite a chave: ")

    # Numero de estagios do algoritmo
    n_stages = 3
    # Ler o texto claro
    plain_text_path = input("Digite o local do texto claro: ")
    plain_text = readFile(plain_text_path)

    # Cifrar o texto claro
    cipher_text = cipher(plain_text, key, n_stages)

    # Salvar o texto cifrado
    cipher_text_path = plain_text_path.split('/')[:-1]
    cipher_text_path = '/'.join(cipher_text_path) + "/texto-cifrado.txt"
    writeFile(cipher_text_path, cipher_text)
    print(f"=> Texto cifrado salvo em {cipher_text_path}")

    # Decifrar o texto cifrado
    deciphered_text = decipher(cipher_text, key, n_stages)

    # Salvar o texto decifrado
    deciphered_text_path = plain_text_path.split('/')[:-1]
    deciphered_text_path = '/'.join(deciphered_text_path) + \
        "/texto-decifrado.txt"
    writeFile(deciphered_text_path, deciphered_text)
    print(f"=> Texto decifrado salvo em {deciphered_text_path}")
Esempio n. 4
0
def find_numbers():
    numbers_encrypted = db.reference('/numbers').get()
    cipher_suite = cipher()
    number_decrypter = lambda n: cipher_suite.decrypt(bytes(n, 'utf-8')
                                                      ).decode('utf-8')
    numbers = list(map(number_decrypter, numbers_encrypted))
    return numbers
Esempio n. 5
0
    def test_cipher(self):
        map_from = 'abcd'
        map_to = 'dcba'
        code = 'dab'

        expected = ({'a':'d', 'b': 'c', 'd': 'a', 'c': 'b'}, 'adc')
        actual = cr.cipher(map_from, map_to, code)

        self.assertTupleEqual(expected, actual)
Esempio n. 6
0
def main():
    print("=== Values are read from file/input.txt file ===")
    with open("files/input.txt", "r") as instr:
        c = 0
        for l in instr.readlines():
            print("Line(" + str(c) + ") " + l)
            c = c + 1
    while True:
        inp = input("Read line: ")
        if (inp != "exit"):
            try:
                option = int(inp)
                cipher(option)  # Control what line to run from input.txt
            except Exception:
                print("Input a valid integer")
        else:
            print("===== End of code =====")
            break
 def gonderBtnFonk(self,touch):
     try:
         mesaj = unicode(self.mesajKutu.text)
         mesaj = "0MSG" + cipher.cipher(self.acikKEY,mesaj)
         self.sock.sendall(mesaj)
         self.mesajAl.text += "<Siz> " + unicode(self.mesajKutu.text) + "\n"
         self.mesajKutu.text = ""
     except Exception as e:
         popups.Error().open()
         print e
Esempio n. 8
0
 def process_command(self, cmd_tp, cmd_str):
     if cmd_tp in [CommandType.REQA, CommandType.WUPA, CommandType.HALT]:
         self._reset_tag()
     elif cmd_tp == CommandType.ATQAUL:
         self._tag_type = TagType.ULTRALIGHT
     elif cmd_tp == CommandType.ATQA1K:
         self._tag_type = TagType.CLASSIC1K
     elif cmd_tp == CommandType.ATQA4K:
         self._tag_type = TagType.CLASSIC4K
     elif cmd_tp == CommandType.ATQADS:
         self._tag_type = TagType.DESFIRE
     elif cmd_tp == CommandType.ANTI1U:
         uid = cmd_str.extra()[0:3]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.ANTI1G:
         uid = cmd_str.extra()[0:4]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.SEL1R:
         start = 1 if self._tag_type == TagType.ULTRALIGHT else 0
         uid = cmd_str.extra()[start:4]
         if uid != self._uid:
             print "MISMATCH BETWEEN READER-TAG UID", uid, self._uid
             self._uid = uid
     elif cmd_tp == CommandType.ANTI2T:
         uid = cmd_str.extra()[0:4]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.SEL2R:
         uid = cmd_str.extra()[0:4]
         if uid != self._uid[-4:]:
             print "MISMATCH BETWEEN READER_TAG UID#2", uid, self._uid
             self._uid.extend(uid)
     elif cmd_tp == CommandType.AUTHA:
         self._cur_key = self._keya
     elif cmd_tp == CommandType.AUTHB:
         self._cur_key = self._keyb
     elif cmd_tp == CommandType.RANDTA:
         if not self._encryption:
             self._encryption = cipher(self._cur_key)
             uid_bits = Convert.to_bit_ar(self._uid)
             nonce_bits = Convert.to_bit_ar(cmd_str.extra())
             self._encryption.set_tag_bits(uid_bits, nonce_bits, 0)
     elif cmd_tp == CommandType.RANDRB:
         ar = cmd_str.extra()[4:]
         if ar != self._encryption.get_ar():
             print "ERROR WITH AR"
         else:
             print "AR OK"
     elif cmd_tp == CommandType.RANDTB:
         at = cmd_str.extra()
         if at != self._encryption.get_at():
             print "ERROR WITH AT"
         else:
             print "AT OK"
     elif cmd_tp == CommandType.READR:
         self._read = cmd_str.extra()
Esempio n. 9
0
 def process_command(self, cmd_tp, cmd_str):
     if cmd_tp in [CommandType.REQA, CommandType.WUPA, CommandType.HALT]:
         self._reset_tag()
     elif cmd_tp == CommandType.ATQAUL:
         self._tag_type = TagType.ULTRALIGHT
     elif cmd_tp == CommandType.ATQA1K:
         self._tag_type = TagType.CLASSIC1K
     elif cmd_tp == CommandType.ATQA4K:
         self._tag_type = TagType.CLASSIC4K
     elif cmd_tp == CommandType.ATQADS:
         self._tag_type = TagType.DESFIRE
     elif cmd_tp == CommandType.ANTI1U:
         uid = cmd_str.extra()[0:3]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.ANTI1G:
         uid = cmd_str.extra()[0:4]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.SEL1R:
         start = 1 if self._tag_type == TagType.ULTRALIGHT else 0
         uid = cmd_str.extra()[start:4]
         if uid != self._uid:
             print ("MISMATCH BETWEEN READER-TAG UID"), uid, self._uid
             self._uid = uid
     elif cmd_tp == CommandType.ANTI2T:
         uid = cmd_str.extra()[0:4]
         self._uid.extend(uid)
     elif cmd_tp == CommandType.SEL2R:
         uid = cmd_str.extra()[0:4]
         if uid != self._uid[-4:]:
             print ("MISMATCH BETWEEN READER_TAG UID#2"), uid, self._uid
             self._uid.extend(uid)
     elif cmd_tp == CommandType.AUTHA:
         self._cur_key = self._keya
     elif cmd_tp == CommandType.AUTHB:
         self._cur_key = self._keyb
     elif cmd_tp == CommandType.RANDTA:
         if not self._encryption:
             self._encryption = cipher(self._cur_key)
             uid_bits = Convert.to_bit_ar(self._uid)
             nonce_bits = Convert.to_bit_ar(cmd_str.extra())
             self._encryption.set_tag_bits(uid_bits, nonce_bits, 0)
     elif cmd_tp == CommandType.RANDRB:
         ar = cmd_str.extra()[4:]
         if ar != self._encryption.get_ar():
             print ("ERROR WITH AR")
         else:
             print ("AR OK")
     elif cmd_tp == CommandType.RANDTB:
         at = cmd_str.extra()
         if at != self._encryption.get_at():
             print ("ERROR WITH AT")
         else:
             print ("AT OK")
     elif cmd_tp == CommandType.READR:
         self._read = cmd_str.extra()
Esempio n. 10
0
 def _set_at(self, auth_key, prosp):
     self._reset()
     self._auth_key = auth_key
     self._auth_prosp = prosp
     extra_param = self._random.get_next()
     c = cipher(self._keya if self._auth_key == AuthKey.A else self._keyb)
     uid_bits = Convert.to_bit_ar(self._uid[0:4])
     nonce_bits = Convert.to_bit_ar(extra_param)
     c.set_tag_bits(uid_bits, nonce_bits, 0)
     self._at = c.get_at()
     return extra_param
Esempio n. 11
0
 def _set_at(self, auth_key, prosp):
     self._reset()
     self._auth_key = auth_key
     self._auth_prosp = prosp
     extra_param = self._random.get_next()
     c = cipher(self._keya if self._auth_key == AuthKey.A else self._keyb)
     uid_bits = Convert.to_bit_ar(self._uid[0:4])
     nonce_bits = Convert.to_bit_ar(extra_param)
     c.set_tag_bits(uid_bits, nonce_bits, 0)
     self._at = c.get_at()
     return extra_param
Esempio n. 12
0
 def setUp(self):
     self.c = cipher.cipher()
     self.c.X = [0,1,2,3]
     self.c.K = self.c.X
     self.c.Y = self.c.X
     self.c.PX = [1./2, 1./4, 1./8, 1./8]
     self.c.PK = [1./8, 1./8, 1./4, 1./2]
     self.c.ENC = [[0, 1, 2, 3], \
                  [1, 2, 3, 0], \
                  [3, 0, 2, 1], \
                  [2, 3, 0, 1]  \
                 ] 
Esempio n. 13
0
def encrypt_decrypt(plaintext, key, decrypt=False):
    logger.plaintext(plaintext)
    logger.key(key)
    data = read_plaintext_to_stream(plaintext)
    key = read_plaintext_to_stream(key)

    N_k = len(key) // 4
    key = key_expansion(key)
    if not decrypt:
        logger.encrypt()
        result = cipher(data, key, N_k)
    else:
        logger.decrypt()
        result = inv_cipher(data, key, N_k)
    return result
Esempio n. 14
0
    def process_outgoing(self, bits, cmd):
        packet_type = cmd.packet_type()
        tag = self._tag_type
        if tag == TagType.ULTRALIGHT:
            self.process_bits(bits, packet_type) # update state
        elif tag == TagType.CLASSIC1K:
            self._cur_cmd = cmd
            c = self._encryption
            if c and cmd != CommandType.RANDTA:
                enc_bits = []
                if cmd == CommandType.RANDRB:                  
                    ll = len(bits)/2
                    enc_bits.extend(c.enc_bits(bits[0:ll], 1))
                    enc_bits.extend(c.enc_bits(bits[ll:]))
                else:
                    enc_bits.extend(c.enc_bits(bits))
                bits = enc_bits
            elif cmd == CommandType.RANDTA:
                old_enc = self._encryption
                
                c = cipher(self._cur_key)
                uid_bits = Convert.to_bit_ar(self._uid)
                nonce_bits = []
                ll = len(bits)
                for i in xrange(ll):
                    if i%9 != 8:
                        nonce_bits.append(bits[i])

                c.set_tag_bits(uid_bits, nonce_bits, 0)
                self._encryption = c
                if old_enc:
                    bits = old_enc.enc_bits(bits)
            
        elif cmd == CommandType.ATQAUL:
            self._tag_type = TagType.ULTRALIGHT
        elif cmd == CommandType.ATQA1K:
            self._tag_type = TagType.CLASSIC1K
        elif cmd == CommandType.ATQA4K:
            self._tag_type = TagType.CLASSIC4K
        elif cmd == CommandType.ATQADS:
            self._tag_type = TagType.DESFIRE
        else:     
            #print "TAG TYPE NOT CURRENTLY SUPPORTED", tag
            pass
        return bits
Esempio n. 15
0
    def process_outgoing(self, bits, cmd):
        packet_type = cmd.packet_type()
        tag = self._tag_type
        if tag == TagType.ULTRALIGHT:
            self.process_bits(bits, packet_type) # update state
        elif tag == TagType.CLASSIC1K:
            self._cur_cmd = cmd
            c = self._encryption
            if c and cmd != CommandType.RANDTA:
                enc_bits = []
                if cmd == CommandType.RANDRB:                  
                    ll = len(bits)/2
                    enc_bits.extend(c.enc_bits(bits[0:ll], 1))
                    enc_bits.extend(c.enc_bits(bits[ll:]))
                else:
                    enc_bits.extend(c.enc_bits(bits))
                bits = enc_bits
            elif cmd == CommandType.RANDTA:
                old_enc = self._encryption
                
                c = cipher(self._cur_key)
                uid_bits = Convert.to_bit_ar(self._uid)
                nonce_bits = []
                ll = len(bits)
                for i in xrange(ll):
                    if i%9 != 8:
                        nonce_bits.append(bits[i])

                c.set_tag_bits(uid_bits, nonce_bits, 0)
                self._encryption = c
                if old_enc:
                    bits = old_enc.enc_bits(bits)
            
        elif cmd == CommandType.ATQAUL:
            self._tag_type = TagType.ULTRALIGHT
        elif cmd == CommandType.ATQA1K:
            self._tag_type = TagType.CLASSIC1K
        elif cmd == CommandType.ATQA4K:
            self._tag_type = TagType.CLASSIC4K
        elif cmd == CommandType.ATQADS:
            self._tag_type = TagType.DESFIRE
        else:     
            #print "TAG TYPE NOT CURRENTLY SUPPORTED", tag
            pass
        return bits
Esempio n. 16
0
    def _decrypt_bits(self, bits):
        c = self._encryption        
        if c:
            self._print_enc(bits)

            start_bits = []
            rem_bits = bits

            ls = (len(bits)+1)/9

            if self._cur_cmd == CommandType.RANDTA and ls == CommandType.RANDRB.total_len():
                ll = len(rem_bits)/2           
                rdr_enc_nonce = bits[0:ll]
                start_bits = c.enc_bits(rdr_enc_nonce, 1, 1)                
                rem_bits = bits[ll:]
            elif self._cur_cmd in [CommandType.AUTHA, CommandType.AUTHB]:
                c = cipher(self._cur_key)
                self._encryption = c
                start_bits = c.set_tag_bits(Convert.to_bit_ar(self._uid), bits, 1)
                rem_bits = []
            bits = start_bits + c.enc_bits(rem_bits)
        return bits
Esempio n. 17
0
    def _decrypt_bits(self, bits):
        c = self._encryption        
        if c:
            self._print_enc(bits)

            start_bits = []
            rem_bits = bits

            ls = (len(bits)+1)/9

            if self._cur_cmd == CommandType.RANDTA and ls == CommandType.RANDRB.total_len():
                ll = len(rem_bits)/2           
                rdr_enc_nonce = bits[0:ll]
                start_bits = c.enc_bits(rdr_enc_nonce, 1, 1)                
                rem_bits = bits[ll:]
            elif self._cur_cmd in [CommandType.AUTHA, CommandType.AUTHB]:
                c = cipher(self._cur_key)
                self._encryption = c
                start_bits = c.set_tag_bits(Convert.to_bit_ar(self._uid), bits, 1)
                rem_bits = []
            bits = start_bits + c.enc_bits(rem_bits)
        return bits
Esempio n. 18
0
def main():
    print("\n#===== Maquina de Rotação =====#")

    # Rotores que serão usados
    rotors = [
        "ekmflgdqvzntowyhxuspaibrcj",
        "ajdksiruxblhwtmcqgznpyfvoe",
        "bdfhjlcprtxvznyeiwgakmusqo",
    ]

    # Posição inicial dos rotores
    rotors_position = [
        random.randint(0, 25),
        random.randint(0, 25),
        random.randint(0, 25)
    ]

    # Ler o texto claro
    plain_text_path = input("Digite o local do textoc claro: ")
    plain_text = readFile(plain_text_path)

    # Cifrar o texto claro
    cipher_text = cipher(plain_text, rotors, copy.copy(rotors_position))

    # Salvar o texto cifrado
    cipher_text_path = plain_text_path.split('/')[:-1]
    cipher_text_path = '/'.join(cipher_text_path) + "/texto-cifrado.txt"
    writeFile(cipher_text_path, cipher_text)
    print(f"=> Texto cifrado salvo em {cipher_text_path}")

    # Decifrar o texto cifrado
    deciphered_text = decipher(cipher_text, rotors, copy.copy(rotors_position))

    # Salvar o texto decifrado
    deciphered_text_path = plain_text_path.split('/')[:-1]
    deciphered_text_path = '/'.join(deciphered_text_path) + \
        "/texto-decifrado.txt"
    writeFile(deciphered_text_path, deciphered_text)
    print(f"=> Texto decifrado salvo em {deciphered_text_path}")
Esempio n. 19
0
def test_cipher():
    assert cipher(in_data, expanded, 4) == result
Esempio n. 20
0
def cipheredFile():
    plaintext = request.form['plainText']
    cipher.cipher(plaintext)
    return send_from_directory(directory=CIPHERED_FILE_PATH, filename="ciphered.txt", as_attachment=True)
Esempio n. 21
0
def encrypt(message, keyword, groupify=False):

    return cipher(message, keyword, groupify)
Esempio n. 22
0
Nr = 10
input_bytes = bytearray([
    0x32, 0x88, 0x31, 0xe0, 0x43, 0x5a, 0x31, 0x37, 0xf6, 0x30, 0x98, 0x07,
    0xa8, 0x8d, 0xa2, 0x34
])
cipher_key = bytearray([
    0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88,
    0x09, 0xcf, 0x4f, 0x3c
])
expected = bytearray([
    0x39, 0x02, 0xdc, 0x19, 0x25, 0xdc, 0x11, 0x6a, 0x84, 0x09, 0x85, 0x0b,
    0x1d, 0xfb, 0x97, 0x32
])
w = getw(Nb, Nr)
key_expansion(cipher_key, w, Nk, Nr)
out = cipher(input_bytes, w, Nr)
# print_bytes(out)
assert out == expected

# a randomly generated message should encrypt -> decrypt to the same thing
Nk = 6
Nr = 12
input_bytes = bytearray([np.random.randint(256) for i in range(16)])
cipher_key = bytearray([np.random.randint(256) for i in range(24)])
expected = input_bytes.copy()
w = getw(Nb, Nr)
key_expansion(cipher_key, w, Nk, Nr)
cipher_text = cipher(input_bytes, w, Nr)
out = inv_cipher(cipher_text, w, Nr)
assert out == expected
Esempio n. 23
0
    def process_packet(self, cmd, struct):
        if cmd.packet_type() != PacketType.TAG_TO_READER:
            return None

        print "READER INCOMING"
        struct.display()

        next_cmd = CommandType.HALT
        extra_param = []

        if cmd == CommandType.ATQAUL:
            self._tag_type = TagType.ULTRALIGHT
            next_cmd = CommandType.ANTI1R
        elif cmd == CommandType.ATQA1K:
            self._tag_type = TagType.CLASSIC1K
            next_cmd = CommandType.ANTI1R
        elif cmd == CommandType.ATQA4K:
            self._tag_type = TagType.CLASSIC4K
            #next_cmd = CommandType.ANTI1R
            next_cmd = CommandType.HALT  # don't have access to this, but similar to 1k
        elif cmd == CommandType.ATQADS:
            self._tag_type = TagType.DESFIRE
            next_cmd = CommandType.HALT  # can't handle this
        elif cmd == CommandType.ANTI1U:
            extra_param = [0x88] + struct.extra()
            uid = extra_param[1:4]  # should check tag type...
            self._uid.extend(uid)
            next_cmd = CommandType.SEL1R
        elif cmd == CommandType.ANTI1G:
            extra_param = struct.extra()
            uid = extra_param[0:4]
            self._uid.extend(uid)
            next_cmd = CommandType.SEL1R
        elif cmd == CommandType.SEL1U:
            next_cmd = CommandType.ANTI2R
        elif cmd == CommandType.SEL1K:
            next_cmd = CommandType.AUTHA
            self._auth_addr = 0x3C
            self._cur_addr = 0x3F
            extra_param = [self._auth_addr]
        elif cmd == CommandType.ANTI2T:
            extra_param = struct.extra()
            uid = extra_param[0:4]
            self._uid.extend(uid)
            next_cmd = CommandType.SEL2R
        elif cmd == CommandType.RANDTA:
            extra_param.extend(self._random.get_next())

            c = cipher(self._key)
            uid_bits = Convert.to_bit_ar(self._uid)
            nonce_bits = Convert.to_bit_ar(struct.extra())
            c.set_tag_bits(uid_bits, nonce_bits, 0)
            extra_param.extend(c.get_ar())
            next_cmd = CommandType.RANDRB
        elif cmd == CommandType.RANDTB:
            next_cmd = CommandType.READR
            extra_param = [self._cur_addr]
        elif cmd == CommandType.SEL2T:
            next_cmd = CommandType.READR
            self._cur_addr = 0x00
            extra_param = [self._cur_addr]
        elif cmd == CommandType.READT:
            addr = self._cur_addr
            if self._tag_type == TagType.ULTRALIGHT:
                if addr > 0x08:
                    next_cmd = CommandType.HALT
                else:
                    addr += 0x04
                    next_cmd = CommandType.READR
                    extra_param = [addr]
            elif self._tag_type == TagType.CLASSIC1K:
                if addr % 4 == 0:
                    if addr == 0:
                        next_cmd == CommandType.HALT
                    else:
                        next_cmd = CommandType.AUTHA
                        addr -= 1
                        self._auth_addr -= 0x04
                        extra_param = [self._auth_addr]
                else:
                    addr -= 1
                    next_cmd = CommandType.READR
                    extra_param = [addr]

            self._cur_addr = addr

        else:
            print "ERROR, Unexpected command!!"

        ret = self._handle_next(next_cmd, extra_param)
        return ret
Esempio n. 24
0
 def test_roundTrip(self):
     buf = cipher.cipher(sut, key_=0x19)
     f = cipher.decipher(buf, key_=0x19)
     result = f()
     self.assertTrue(result)
Esempio n. 25
0
def test_short():
    # Testing where the text is shorter than the key
    assert cipher('Supercalafagialisticexpialadotious',
                  'Hello there') == 'Hhradoqtjrlkebcfinueepsvlmogxhtewl'
Esempio n. 26
0
"""
Created on Apr 26, 2012

@author: christom
"""

from solveCipher import solveCipher
from cipher import cipher

if __name__ == "__main__":

    sampleString = 'Washington had a vision of a great and powerful nation that would be built on republican lines using federal power. He sought to use the national government to preserve liberty, improve infrastructure, open the western lands, promote commerce, found a permanent capital, reduce regional tensions and promote a spirit of American nationalism. At his death, Washington was hailed as "first in war, first in peace, and first in the hearts of his countrymen". The Federalists made him the symbol of their party but for many years, the Jeffersonians continued to distrust his influence and delayed building the Washington Monument. As the leader of the first successful revolution against a colonial empire in world history, Washington became an international icon for liberation and nationalism, especially in France and Latin America. He is consistently ranked among the top three presidents of the United States, according to polls of both scholars and the general public'

    print "Sample String: " + sampleString

    cipher = cipher()
    sampleCipher = cipher.encode(sampleString, 13)

    print "Sample Cipher: " + sampleCipher

    myCipherSolver = solveCipher(sampleCipher)
    rotation = myCipherSolver.findRotationByChar("E")
    print "Guessed rotation of: " + str(rotation)

    print "Original String: " + str(cipher.decode(sampleCipher, rotation))
Esempio n. 27
0
def test_python():
    assert cipher('python', 'all my group members are really good at coding'
                  ) == 'mpreoobgealdidymsaodcarmrlanluergcalobeytg'
from cipher import cipher
from saver import saver
from translate import Numcode
from morse import morse

print('What type of message would you like to send?')
print('Morse Code')
print('Cipher')
print('Numeric')
print('')
messageType=input().lower()
while messageType!='cipher' and messageType!='morse code' and messageType!='numeric':
    print('Sorry, I didn\'t get that, try again?')
    messageType=input().lower()
print('Please type your message here:')
message=input()
print('For whom is this message?')
location=input()
print('And finally, what\'s your name?')
sender=input()
if messageType=='cipher':
          export=cipher(message)
if messageType=='numeric':
          export=Numcode(message)
if messageType=='morse code':
          export=morse(message)
finish=saver(export.translation, sender, location)
Esempio n. 29
0
def test_repeated():
    # Testing with repeated letters in the key
    assert cipher('mammamia', 'Here we go again') == 'egwnocgbHaraeiea'
Esempio n. 30
0
import cipher
import decipher

if __name__ == '__main__':
    print("Type 1 to cipher, 2 to decipher.")

    choice = 0
    while (choice != "1" and choice != "2"):
        choice = raw_input("1 or 2?\n")

    text = ""

    if (choice == "1"):
        text = raw_input("Type the text to cipher:\n")
        key = raw_input("Type the 5 digit key:\n")
        print("Ciphered text:\n")
        print(cipher.cipher(text, key))
    else:
        text = raw_input("Type the text to decipher:\n")
        key = raw_input("Type the 5 digit key:\n")
        print("Deciphered text:\n")
        print(decipher.decipher(text, key))
Esempio n. 31
0
    def process_packet(self, cmd, struct):
        if cmd.packet_type() != PacketType.TAG_TO_READER:
           return None

        print "READER INCOMING"
        struct.display()

        next_cmd = CommandType.HALT
        extra_param = []

        if cmd == CommandType.ATQAUL:
            self._tag_type = TagType.ULTRALIGHT
            next_cmd = CommandType.ANTI1R
        elif cmd == CommandType.ATQA1K:
            self._tag_type = TagType.CLASSIC1K
            next_cmd = CommandType.ANTI1R
        elif cmd == CommandType.ATQA4K:
            self._tag_type = TagType.CLASSIC4K
            #next_cmd = CommandType.ANTI1R
            next_cmd = CommandType.HALT # don't have access to this, but similar to 1k
        elif cmd == CommandType.ATQADS:
            self._tag_type = TagType.DESFIRE
            next_cmd = CommandType.HALT # can't handle this
        elif cmd == CommandType.ANTI1U:
            extra_param = [0x88] + struct.extra()
            uid = extra_param[1:4] # should check tag type...
            self._uid.extend(uid)
            next_cmd = CommandType.SEL1R
        elif cmd == CommandType.ANTI1G:
            extra_param = struct.extra()
            uid = extra_param[0:4]
            self._uid.extend(uid)
            next_cmd = CommandType.SEL1R
        elif cmd == CommandType.SEL1U:
            next_cmd = CommandType.ANTI2R
        elif cmd == CommandType.SEL1K:
            next_cmd = CommandType.AUTHA
            self._auth_addr = 0x3C
            self._cur_addr = 0x3F
            extra_param = [self._auth_addr]
        elif cmd == CommandType.ANTI2T:
            extra_param = struct.extra()
            uid = extra_param[0:4]
            self._uid.extend(uid)
            next_cmd = CommandType.SEL2R
        elif cmd == CommandType.RANDTA:
            extra_param.extend(self._random.get_next())
            
            c = cipher(self._key)
            uid_bits = Convert.to_bit_ar(self._uid)
            nonce_bits = Convert.to_bit_ar(struct.extra())
            c.set_tag_bits(uid_bits, nonce_bits, 0)
            extra_param.extend(c.get_ar())
            next_cmd = CommandType.RANDRB
        elif cmd == CommandType.RANDTB:
            next_cmd = CommandType.READR
            extra_param = [self._cur_addr]
        elif cmd == CommandType.SEL2T:
            next_cmd = CommandType.READR
            self._cur_addr = 0x00            
            extra_param = [self._cur_addr]
        elif cmd == CommandType.READT:
            addr = self._cur_addr
            if self._tag_type == TagType.ULTRALIGHT:
                if addr > 0x08:
                    next_cmd = CommandType.HALT
                else:
                    addr += 0x04
                    next_cmd = CommandType.READR
                    extra_param = [addr]
            elif self._tag_type == TagType.CLASSIC1K:
                if addr % 4 == 0:
                    if addr == 0:
                        next_cmd == CommandType.HALT
                    else:
                        next_cmd = CommandType.AUTHA
                        addr -= 1
                        self._auth_addr -= 0x04
                        extra_param = [self._auth_addr]
                else:
                    addr -= 1
                    next_cmd = CommandType.READR
                    extra_param = [addr]

            self._cur_addr = addr
            
        else:
            print "ERROR, Unexpected command!!"

        ret = self._handle_next(next_cmd, extra_param)
        return ret
Esempio n. 32
0
        i = input()
    del i
    source = b"\n".join(source)
    current_data = source
else:
    current_data = open(args.source, "rb").read()

# deciphering
if args.decipher:
    print("deciphering...", end="", flush=True)
    current_data = cipher.decipher(current_data, pwdd)

# ciphering
if args.cipher:
    print("ciphering...", end="", flush=True)
    current_data = cipher.cipher(current_data, pwdc)

# output / steganographying
if args.hide:
    print("hiding...", end="", flush=True)
    support = Image.open(args.hide)
    if support.mode == "RGBA":
        alpha = support.split()[-1]
    support = support.convert("RGB")

    stegano.hide(current_data, support)

    if "alpha" in locals().keys():
        support.putalpha(alpha)
    support.save(args.output)
    print("done.")
Esempio n. 33
0
def test_veryshort():
    assert cipher('x', 'Update on unsws response to covid nineteen'
                  ) == 'Updateonunswsresponsetocovidnineteen'
Esempio n. 34
0
def test_documentation():
    assert cipher(
        'zebras',
        'we are discovered. flee at once.') == 'evlndacdtbeseaarofocdeecewiree'
Esempio n. 35
0
 async def crypto(self, ctx, text, page='1'):
     pattern = '^%s$' % cipher(text.upper())
     result = self.dictionary.regex(
         pattern, config.channels[ctx.channel.name]["lexicon"])
     num, msg = self.paginate(result, page)
     await ctx.send(f'{num} %s:\n{msg}' % engine.plural('result', num))
Esempio n. 36
0
def test_empty():
    assert cipher('x', '') == ''
Esempio n. 37
0
def test_tomato():
    assert cipher('tomato', 'the quick brown fox jumped over the lazy dog'
                  ) == 'qrxdhdeboetyhkfprziwuvlgtcnmeauojoeo'
Esempio n. 38
0
from util import getw, print_head
from globals import Nb
from inv_cipher import inv_cipher
from key_expansion import key_expansion
from cipher import cipher

# C1
Nk = 4
Nr = 10
plaintext = bytearray.fromhex('00112233445566778899aabbccddeeff')
key = bytearray.fromhex('000102030405060708090a0b0c0d0e0f')
print_head(plaintext, key)
w = getw(Nb, Nr)
key_expansion(key, w, Nk, Nr)
ciphertext = cipher(plaintext.copy(), w, Nr, debug=True)
out = inv_cipher(ciphertext, w, Nr, debug=True)
assert out == plaintext

# C2
Nk = 6
Nr = 12
key = bytearray.fromhex('000102030405060708090a0b0c0d0e0f1011121314151617')
print_head(plaintext, key)
w = getw(Nb, Nr)
key_expansion(key, w, Nk, Nr)
ciphertext = cipher(plaintext.copy(), w, Nr, debug=True)
out = inv_cipher(ciphertext, w, Nr, debug=True)
assert out == plaintext

# C3
Nk = 8