Exemple #1
0
def encrypt_factory(cypher = None,Seed = None):
    """ creates an encryptor and a decryptor function from a cypher, or a seed, or randomly
    """

    if not cypher:
        cypher = make_cypher(Seed)
    trans = mt(alphabet,cypher)
    untrans = mt(cypher,alphabet)
    def encryptor(message):
        return message.lower().translate(trans)
    def decryptor(message):
        return message.lower().translate(untrans)
    return encryptor, decryptor
# -*- coding: utf-8 -*-

from string import maketrans as mt

translation = mt('GCTA', 'CGAU')


def to_rna(DNAstrand):
    return DNAstrand.translate(translation)
def encryptor(key, message):
    key %= 26
    return message.translate(mt(lc+uc, lc[key:]+lc[:key]+uc[key:]+uc[:key]))
Exemple #4
0
    # print D(" ".join(cypherbet)) # uncomment to cheat

    answer = None
    try:
        while not answer:
            answer = raw_input(" ".join(cypherbet)+"\n")
            if not answer:
                print "Please enter some text or ^C to exit"
            else:
                decypher = "".join([ch for ch in answer if ch.isalpha()])
                if len(decypher) != len(cypherbet):
                    print "\nPlease enter the correct number of characters."
                    answer = ""
    except KeyboardInterrupt:
        print "Thanks for trying!"
        exit()

    # test answer

    decypher_table = mt(cypherbet,decypher)

    print 80*"="

    try:
        assert cyphertext.translate(decypher_table) == long_message.lower()
    except:
        print "\n\nSorry. It should have been:\n%s\n%s" % (" ".join(cypherbet)," ".join(D(cypherbet)))
    else:
        print "\n\nYes!\n"
    
 def decode(cls, s):
     self = cls
     mtt = mt(self.__enc, self.__alpha)
     return s.translate(mtt)
 def encode(cls, s):
     self = cls
     tmp = s.lower().translate(None, pct + wht + dig)
     mtt = mt(self.__alpha, self.__enc)
     return tmp.translate(mtt)
Exemple #7
0
def encryptor(key, message):
    key %= 26
    return message.translate(
        mt(lc + uc, lc[key:] + lc[:key] + uc[key:] + uc[:key]))