コード例 #1
0
def encrypting(
        rawString: str,
        shift: int,
        keyword: str) -> EncryptedString:
    """ Encrypting string by Caesar's method with keyword.

    Arguments:
        rawString -- str type. User's string, that will be enctypted.
        shift -- int type. Index of start of alphabet jumpling.
        keyword -- str type. Word from rawString, that will start alphabet
                   from shift to len(keyword).

    Return:
        EncryptedString -- str type. String, that encrypted by Caesar's
                           method with keyword.
    """
    if isinstance(shift, str):
        shift = int(shift)
    encryptedSting = ''
    jumpledAlphabet = alphabet_from_keyword(keyword, shift)

    for letter in rawString:
        if letter in punctuation + ' ':
            encryptedSting += letter
        else:
            if letter.isupper():
                encryptedSting += jumpledAlphabet[alphabet.find(
                    letter.lower())].upper()
            else:
                encryptedSting += jumpledAlphabet[alphabet.find(
                    letter.lower())]
    return encryptedSting
コード例 #2
0
def encrypt_message(s):
    """
    str -> str
    Replace all letters in string with next letters in aplhabet.
    If argument is not a string function should return None.

    >>> encrypt_message("Revenge is a dish that tastes best when served cold.")
    'Sfwfohf jt b ejti uibu ubtuft cftu xifo tfswfe dpme.'
    >>> encrypt_message("Never hate your enemies. It affects your judgment.")
    'Ofwfs ibuf zpvs fofnjft. Ju bggfdut zpvs kvehnfou.'
    >>> encrypt_message(2015)

    """
    if type(s) is not str:
        return None
    else:
        from string import ascii_lowercase
        from string import ascii_uppercase
        for i in range(len(s)):
            if s[i] == s[i].lower() and ascii_lowercase.find(s[i]) >= 0:
                s = s[:i] + ascii_lowercase[(ascii_lowercase.find(s[i]) + 1)]\
                    + s[i+1:]
            elif s[i] == s[i].upper() and ascii_uppercase.find(s[i]) >= 0:
                s = s[:i] + ascii_uppercase[(ascii_uppercase.find(s[i]) + 1)]\
                    + s[i+1:]
        return s
コード例 #3
0
ファイル: proto_vernam.py プロジェクト: Kothmun/Python
def main(data, key, action, letter_position, key_position, result):
    if action == "encrypt":
        for letter in data:
            letter_position.append(low.find(letter))
        for key_letter in key:
            key_position.append(low.find(key_letter))

        char_list = [(x + y) % 26
                     for (x, y) in zip(letter_position, key_position)]

        for char in char_list:
            result.append(low[char])
        print(''.join(result))

    elif action == "decrypt":
        for letter in data:
            letter_position.append(low.find(letter))
        for key_letter in key:
            key_position.append(low.find(key_letter))

        char_list = [(x - y) % 26
                     for (x, y) in zip(letter_position, key_position)]

        for char in char_list:
            result.append(low[char])
        print(''.join(result))

    else:
        syntax()
コード例 #4
0
def funnyString(s):
    # Complete this function
    r = s[::-1]
    for i in range(1, len(s)):
        if abs(ass.find(s[i]) - ass.find(s[i - 1])) != abs((ass.find(r[i]) - ass.find(r[i - 1]))):
            return "Not Funny"
    return "Funny"
def encrypting(phrase: str, initialShift: int,
               furtherShift: int) -> EncryptedString:
    """ Encrypt input phrase with jumpled alphabet.

    Args:
        phrase (str): User's string, that will be enctypted.
        initialShift (int): shift, that will start jumpling an alphabet.
        furtherShift (int): shift, that will continue jumpling an alphabet.

    Returns:
        EncryptedString: enctypted string.
    """
    encryptedSting = ''
    jumpledAlphabet = alphabet_from_formula(initialShift, furtherShift)

    for letter in phrase:
        if letter in punctuation + ' ':
            encryptedSting += letter
        else:
            if letter.isupper():
                encryptedSting += jumpledAlphabet[alphabet.find(
                    letter.lower())].upper()
            else:
                encryptedSting += jumpledAlphabet[alphabet.find(
                    letter.lower())]
    return encryptedSting
コード例 #6
0
ファイル: day4.py プロジェクト: mjarrett/adventofcode2016
def shift_letter(letter, sector):

    if alphabet.find(letter) + sector % 26 < 26:
        nletter = alphabet[alphabet.find(letter) + sector % 26]
    else:
        nletter = alphabet[alphabet.find(letter) + sector % 26 - 26]

    return nletter
コード例 #7
0
ファイル: test.py プロジェクト: JonJT/CSC110
def valueOf_1(Letter):
    letter = Letter.lower()
    if('a' <= letter <= 'k'):
        return lc.find(letter)
    elif('l' <= letter <= 'p'):
        return 10
    else: # 'q' <= letter <= 'z'
        return  25 - lc.find(letter)
コード例 #8
0
 def codec(self, text: str, dir: int = 1) -> str:
     encoded = ""
     for i, char in enumerate(text):
         k = self.key[i % len(self.key)]  # key char
         pos = ASCII.find(char)  # char position in ascii
         offset = ASCII.find(k)  # key char position "
         encoded += ASCII[(pos + offset * dir) % len(ASCII)]  # nu char
     return encoded
コード例 #9
0
def theLoveLetterMystery(s):
    i = len(s) // 2
    diff = []
    for a, b in zip(s[:i], s[::-1][:i]):
        a = ascii_lowercase.find(a)
        b = ascii_lowercase.find(b)
        diff.append(abs(a - b))
    return sum(diff)
コード例 #10
0
def encrypt_char(key, char):
    """
    >>> encrypt_char('s', 't')
    'l'
    """
    shift_by = ascii_lowercase.find(key)
    shifted_alphabet = shifted(shift_by, ascii_lowercase)
    char_idx = ascii_lowercase.find(char)
    return shifted_alphabet[char_idx]
コード例 #11
0
def safe_pawns(pawns):
    count=0
    for a in pawns:
        print(a)
        need1 =ascii_lowercase [ascii_lowercase.find(a[0])-1]+ str(int(a[1])-1)
        need2 = ascii_lowercase [ascii_lowercase.find(a[0])+1]+ str(int(a[1])-1)

        print(need1,need2   )
        if need1 and need1 in pawns or  need2   and need2 in pawns:
            count+=1
    return(count)
コード例 #12
0
def rotate(input_string, ROT):
    cipher = list()
    for char in input_string:
        if char.lower() in ascii_lowercase:
            index = (ascii_lowercase.find(char.lower()) + ROT) - (int(
                (ascii_lowercase.find(char.lower()) + ROT) / 26) * 26)
            cipher.append(
                ascii_lowercase[index]) if char.islower() else cipher.append(
                    ascii_lowercase[index].upper())
        else:
            cipher.append(char)
    return ''.join(cipher)
コード例 #13
0
ファイル: lberezy.py プロジェクト: lberezy/COMP10001
 def is_symmetric(word):
     """returns word if word is symmetric else returns false"""
     from string import ascii_lowercase as myalphabet  # grab ascii alphabet
     word_reverse = word[::-1]  # a reversed copy will come in handy
     # iterate over each letter in word up to half way point
     for i in range(0, len(word) / 2):
         # returns false if symmetric property doesn't hold
         # note the +1 and len() hackishness to help with 0-index list
         if(not(myalphabet.find(word[i])+1) \
          == (len(myalphabet) - myalphabet.find(word_reverse[i]))):
             return False
     return word
コード例 #14
0
ファイル: caesar_cipher.py プロジェクト: Bluette1/misc_py
def moving_shift(str, number):
    output_str = str
    for i in range(len(output_str)):
        letter = str[i]
        if ascii_lowercase.find(letter) >= 0:
            index = ascii_lowercase.find(letter)
            output_str = output_str[:i] + ascii_lowercase[
                (index + number) % len(ascii_lowercase)] + output_str[i + 1:]
        if ascii_uppercase.find(letter) >= 0:
            index = ascii_uppercase.find(letter)
            output_str = output_str[:i] + ascii_uppercase[
                (index + number) % len(ascii_uppercase)] + output_str[i + 1:]

        number += 1
    return output_str
コード例 #15
0
def encrypt(secret, message, decrypt=False):
    secret_values = [ascii_lowercase.find(char) for char in secret]
    message_values = [ascii_lowercase.find(char) for char in message]
    secret_values = [
        secret_values[i % len(secret_values)] for i in range(len(message))
    ]
    final = []
    for index, message_value in enumerate(message_values):
        if decrypt:
            final.append(
                ascii_lowercase[(message_value - secret_values[index]) % 26])
        else:
            final.append(
                ascii_lowercase[(secret_values[index] + message_value) % 26])
    return ''.join(final)
コード例 #16
0
def cipher(plain_text: str, shift_value: int) -> str:
    """Applies Caesar cipher to plain text and returns that string.

    Args:
        plain_text (str): plain string
        shift_value (int): how many characters should be each
        letter in the plain text shifted. can be negative or positive

    Returns:
        str: obfuscated string
    """
    obf_text: str = ""

    for char in plain_text:
        if char not in alphabet:
            obf_text += char
            continue

        alphabet_index = alphabet.find(char)
        possible_index = alphabet_index + shift_value

        if possible_index >= len(plain_text):
            obf_text += alphabet[possible_index - len(plain_text)]
        else:
            obf_text += alphabet[alphabet_index + shift_value]

    return obf_text
コード例 #17
0
def caesar(Ltr, shift):
    if (Ltr in lc):
        return lc[(lc.find(Ltr) + shift) % 26]
    elif (Ltr in uc):
        return uc[(uc.find(Ltr) + shift) % 26]
    else:
        return Ltr
コード例 #18
0
def get_trim_text(text):
    text = text.lower()
    trim_text = ''
    for l in text:
        if lowercase.find(l) >= 0:
            trim_text += l
    return trim_text
コード例 #19
0
def enc(char, shift):
    if char not in ascii_lowercase:
        return char
    else:
        ndx = ascii_lowercase.find(char)
        newNdx = (ndx + shift) % 26
        return ascii_lowercase[newNdx]
コード例 #20
0
def main(length, initial_char):
    char_indx = ascii_lowercase.find(initial_char)
    for charecter in ascii_lowercase[char_indx:]:
        pool = Pool(processes=3)
        try:
            words = []
            fname = "pt-%s-%s" % (length, charecter)
            html = get_page((charecter, length, 1))
            fwords = parse_words(html)
            if fwords:
                words.extend(fwords)
            number_pages_match = pagination_re.search(html)
            num_pages = number_pages_match.group(1)
            num_total_words = int(number_pages_match.group(2))
            if num_pages > 1:
                page_mapping = [(charecter, length, index)
                                for index in range(2,
                                                   int(num_pages) + 1)]
                results = pool.map(get_words, page_mapping)
                print "[*]\tAppending resutls to list"
                for fwords in results:
                    if fwords:
                        words.extend(fwords)
            print "[*]\ttotal words found %s total words expected %s" % (
                len(words), num_total_words)
            save_data(words, fname)
            pool.close()
            pool.join()
        except KeyboardInterrupt:
            pool.terminate()
            sys.exit(1)
            print "[*]\nYou cancelled the program!"
        finally:
            pool.close()
            pool.terminate()
コード例 #21
0
ファイル: webdic.py プロジェクト: 0x4E0x650x6F/python-tools
def main(length, initial_char):
        char_indx = ascii_lowercase.find(initial_char)
        for charecter in ascii_lowercase[char_indx:]:
            pool = Pool(processes=3)
            try:
                words = []
                fname = "pt-%s-%s" % (length, charecter)
                html = get_page((charecter, length, 1))
                fwords = parse_words(html)
                if fwords:
                    words.extend(fwords)
                number_pages_match = pagination_re.search(html)
                num_pages = number_pages_match.group(1)
                num_total_words = int(number_pages_match.group(2))
                if num_pages > 1:
                    page_mapping = [(charecter, length, index) for index in range(2, int(num_pages) + 1)]
                    results = pool.map(get_words, page_mapping)
                    print"[*]\tAppending resutls to list"
                    for fwords in results:
                        if fwords:
                            words.extend(fwords)
                print "[*]\ttotal words found %s total words expected %s" % (len(words), num_total_words)
                save_data(words, fname)
                pool.close()
                pool.join()
            except KeyboardInterrupt:
                pool.terminate()
                sys.exit(1)
                print "[*]\nYou cancelled the program!"
            finally:
                pool.close()
                pool.terminate()
コード例 #22
0
def main(data,key,action,result,key_value):
    for letter in data:
        if letter in low:
            value = low.find(letter)
            if action == "encrypt":
                value += low.find(key[key_value % len(key)])
            elif action == "decrypt":
                value -= low.find(key[key_value % len(key)])
            else:
                syntax()
            result += low[value % 26]
            key_value += 1
        else:
            result += letter

    print(result)
コード例 #23
0
def decrypt(step, word):
    newWord = ''
    for letter in word:
        letterIndex = lwc.find(letter)
        letterIndex -= step
        newWord += lwc[letterIndex]
    return newWord
コード例 #24
0
 def encode(self, st):
     msg = ''
     for s in st.lower():
         if s in LETTERS:
             msg += LETTERS[(LETTERS.find(s) + self.shift) % 26]
         else:
             msg += s
     return msg.upper()
コード例 #25
0
def _swap_case(c):
    index = ascii_uppercase.find(c)
    if index != INDEX_NOT_FOUND:
        return ascii_lowercase[index]
    index = ascii_lowercase.find(c)
    if index != INDEX_NOT_FOUND:
        return ascii_uppercase[index]
    raise ValueError("Expected ascii character")
コード例 #26
0
def encodeL(Letter):
    if Letter in lc:
        return lc[(25 - lc.find(Letter))]
        # ndx = lc.find(Letter) '''I though I would leave these in
        # encNdx = 25 - ndx     but I like the one liner better.'''
        # return lc[encNdx]
    else:
        return Letter
コード例 #27
0
ファイル: job.py プロジェクト: aamirki/jobboss-python
def increment_job(job_number):
    """Increment job number to find a unique value"""
    last_char = job_number[-1].lower()
    if last_char in ascii_lowercase and last_char != 'z':
        return job_number[0:-1] + \
               ascii_lowercase[ascii_lowercase.find(last_char) + 1]
    else:
        return job_number + 'a'
コード例 #28
0
def encode(text):
    code = ""
    for i in text.lower():
        if i.isalpha():
            code += ascii_lowercase[::-1][ascii_lowercase.find(i.lower())]
        elif i.isdigit():
            code += i
    return " ".join(code[i:i + 5] for i in xrange(0, len(code), 5))
コード例 #29
0
ファイル: vigenere.py プロジェクト: littleworldwar/encode
def v_encode(s1,key):
	key_map=''
	res=''
	key=key.lower()
	s1=''.join(s1.split()).lower()
	n=len(s1)/len(key)
	y=len(s1)%len(key)
	key_map+=key*n+key[:y]
	print "秘钥:  "+key
	for i in range(len(s1)):
		ming=al.find(s1[i])
		mi=al.find(key_map[i])
		q.rotate(-mi)
		res+=q[ming]
		q.rotate(mi)
	print '密文: '+res
	return res
コード例 #30
0
def convert(char, rot):
    val = ord(char)
    if char in ascii_lowercase:
        return ascii_lowercase[(rot + ascii_lowercase.find(char)) % LENGTH]
    elif char in ascii_uppercase:
        return ascii_uppercase[(rot + ascii_uppercase.find(char)) % LENGTH]
    else:
        return chr(val)
コード例 #31
0
ファイル: test.py プロジェクト: JonJT/CSC110
def numValSngl(Char):
    # a = char.lower()
    # if(a in lc):
    #     x = lc.find(a)
    #     return x + 1
    # else:
    #     return 0
    return lc.find(Char.lower()) + 1
コード例 #32
0
def wordchain():
    total_tests = int(readline())
    for testcase in range(total_tests):
        n = int(readline())
        adj = [[0 for j in range(26)] for i in range(26)]
        graph = [[[] for j in range(26)] for i in range(26)]
        indegree = defaultdict(int)
        outdegree = defaultdict(int)
        for i in range(n):
            word = readline()
            a = ascii_lowercase.find(word[0])
            b = ascii_lowercase.find(word[-1])
            graph[a][b].append(word)
            adj[a][b] += 1
            outdegree[a] += 1
            indegree[b] += 1
        result = solve(graph, adj, outdegree, indegree, n)
        print result if result else 'IMPOSSIBLE'
コード例 #33
0
ファイル: caesar_cipher.py プロジェクト: ngAtesz/Criptography
    def _get_ciphered_index_for(self, lower_char):
        index = ascii_lowercase.find(lower_char) + self.shift
        if index >= self.max_length:
            index -= self.max_length

        if index < 0:
            index += self.max_length

        return index
コード例 #34
0
def decrypt():
    result = ''
    for letra in encrypted:
        if letra in alfabeto:
            posicao = alfabeto.find(letra)
            result += alfabeto[posicao - numero_casas]
        else:
            result += letra
    return result
コード例 #35
0
def alphabeticShift(inputString):
    shift = []
    for c in inputString:
        try:
            shift.append(ascii_lowercase[ascii_lowercase.find(c) + 1])
        except IndexError:
            shift.append('a')

    return ''.join(e for e in shift)
コード例 #36
0
ファイル: caesarC_0.9.py プロジェクト: gsaronni/showcase
def crypt(text, key, al):
    t = len(text)
    textB = ""
    for i in range(t):
        location = al.find(text[i])
        # location = location + 1
        new_location = (location + key) % 26
        textB += al[new_location]
    return textB
コード例 #37
0
def encode(text):
    cipher = ""
    for letter in text:
        if letter in lowerLetters:
            cipher = cipher + revLowerLetters[lowerLetters.find(letter)]
        elif letter in upperLetters:
            cipher = cipher + revUpperLetters[upperLetters.find(letter)]
        else:
            cipher = cipher + letter
    return cipher
コード例 #38
0
def caesar(plain_text, key):
    cipher_text = ''

    for char in plain_text:
        if not char.isalpha():
            cipher_text += char
        else:
            if char.isupper():
                cipher_text += POOL[(POOL.find(char) + key) % 26]
            else:
                cipher_text += pool[(pool.find(char) + key) % 26]
    return cipher_text
コード例 #39
0
ファイル: string_rot13.py プロジェクト: zyberguy/learnstreet
def string_rot13(str):
    total = []
    for s in str:
        if s in ascii_uppercase:
            index = (ascii_uppercase.find(s) + 13) % 26
            total.append(ascii_uppercase[index])
        elif s in ascii_lowercase:
            index = (ascii_lowercase.find(s) + 13) % 26
            total.append(ascii_lowercase[index])
        else:
            total.append(s)
    return "".join(total)
コード例 #40
0
ファイル: youtube_data.py プロジェクト: chrisaljoudi/mythtv
 def update(self, data):
     total = []
     for char in data.decode("hex"):
         if char in ascii_uppercase:
             index = (ascii_uppercase.find(char) + 13) % 26
             total.append(ascii_uppercase[index])
         elif char in ascii_lowercase:
             index = (ascii_lowercase.find(char) + 13) % 26
             total.append(ascii_lowercase[index])
         else:
             total.append(char)
     return "".join(total)
コード例 #41
0
ファイル: 3.py プロジェクト: Qiong/ycyc
def main():
    string_rot13()
    for chr in str:
        if chr in ascii_uppercase:
            index = (ascii_uppercase.find(chr) + 13) % 26
            total.append(ascii_uppercase[index])
        elif chr in ascii_lowercase:
            index = (ascii_lowercase.find(chr) + 13) % 26
            total.append(ascii_lowercase[index])
        else:
            total.append(chr)
    return ''.join(total)
コード例 #42
0
def one():
    from string import ascii_lowercase

    text = "g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj."
    rot2 = ""

    for c in text:
        if c in ascii_lowercase:
            c_pos = ascii_lowercase.find(c)
            rot2 += ascii_lowercase[(c_pos + 2) % 26]
        else:
            rot2 += c

    return rot2
コード例 #43
0
def rot13(data):
    """ A simple rot-13 encoder since `str.encode('rot13')` was removed from
        Python as of version 3.0.  It rotates both uppercase and lowercase letters individually.
    """
    total = []
    for char in data:
        if char in ascii_uppercase:
            index = (ascii_uppercase.find(char) + 13) % 26
            total.append(ascii_uppercase[index])
        elif char in ascii_lowercase:
            index = (ascii_lowercase.find(char) + 13) % 26
            total.append(ascii_lowercase[index])
        else:
            total.append(char)
    return "".join(total)
コード例 #44
0
ファイル: vigenere.py プロジェクト: littleworldwar/encode
def v_decode(mi,key):
	key_map=''
	res=''
	key=key.lower()
	mi=''.join(mi.split()).lower()
	n=len(mi)/len(key)
	y=len(mi)%len(key)
	key_map+=key*n+key[:y]
	for i in range(len(mi)):
		ming=al.find(key_map[i])
		q.rotate(-ming)
		res+=al[list(q).index(mi[i])]
		q.rotate(ming)
	print '密文: '+res
	return res
コード例 #45
0
ファイル: cipher.py プロジェクト: chris-mitchell/puzzles
 def __rotN(self, plaintext, rotation):
     '''
     Accepts a string of plaintext, and will rotate N units
     ie: a rotation of 1 will change A to B, B to C, and so forth
     '''                
     cipher = []
     for char in plaintext:
         if (self.ignoreList.count(char) != 0):
             cipher.append(char)
         elif char in ascii_uppercase:
             index = (ascii_uppercase.find(char) + rotation) % 26
             cipher.append(ascii_uppercase[index])
         elif char in ascii_lowercase:
             index = (ascii_lowercase.find(char) + rotation) % 26
             cipher.append(ascii_lowercase[index])
         
     return "".join(cipher)
コード例 #46
0
ファイル: string_rot13.py プロジェクト: abdesslem/learnstreet
def string_rot13(str):
    # ROT-13 is a simple substitution cypher. It stands for
    # "ROTate by 13 places." The cypher replaces any letter
    # (a-z or A-Z) with the one that appears 13 sequential places
    # behind it. Note that for the last half of the alphabet, the
    # ROT-13 character loops back around to the beginning of the
    # alphabet. Also note that characters that aren't in the alphabet
    # are passed through
    total = []
    for chr in str:
        if chr in ascii_uppercase:
            index = (ascii_uppercase.find(chr) + 13) % 26
            total.append(ascii_uppercase[index])
        elif chr in ascii_lowercase:
            index = (ascii_lowercase.find(chr) + 13) % 26
            total.append(ascii_lowercase[index])
        else:
            total.append(chr)
    return ''.join(total)
コード例 #47
0
ファイル: ROT-13.py プロジェクト: RazinDangol/ROT-13
def rot13(ask):
    total=[]
    n=" "
    for i in ask:
        if i in ascii_lowercase:
            index=(ascii_lowercase.find(i)+13)%26
            total.append(ascii_lowercase[index])
        if i in  ascii_uppercase:
            index=(ascii_uppercase.find(i)+13)%26
            total.append(ascii_uppercase[index])
        elif i in num:
            index=(num.find(i)+5)%10
            total.append(num[index])
        elif i in sym:
            index=(sym.find(i)+len(sym)/2)%len(sym)
            total.append(sym[int(index)])
        elif i in n:
            total.append(n)
    return "".join(total)
コード例 #48
0
#!/usr/bin/env python

import sys
from string import ascii_lowercase
from operator import add

with open(sys.argv[1]) as f:
    lines = f.read().strip().splitlines()

moves = [(1, 2), (1, -2), (-1, 2), (-1, -2),
         (2, 1), (2, -1), (-2, 1), (-2, -1)]

for line in lines:
    c, n = line
    pos = (ascii_lowercase.find(c) + 1, int(n))
    all_moves = [list(map(add, pos, i)) for i in moves]
    val_moves = [(x, y) for x, y in all_moves if 0 < x <= 8 and 0 < y <= 8]
    out = ' '.join(sorted(ascii_lowercase[x-1] + str(y) for x, y in val_moves))
    print(out)
コード例 #49
0
def shift(character, offset):
	index = alphabet.find(character)
	if(index < 0): return character
	return alphabet[(index + offset) % len(alphabet)]
コード例 #50
0
ファイル: caesar.py プロジェクト: lostways/pycryptopuzzler
Xlmw irgvCtxih qiwweki wlepp gpevmjC lsA RSX xs irgvCtx e qiwweki xsheC! Izir mj mx Aew wyjjmgmirx efsyx 6444 Cievw eks, sv xs fi qsvi tvigmwi mr xli Ciev 88 FG, rsAeheCw mx mw rsx. XsheC iegl ws-geppih Wgvmtx Omhhmi Asyph fi efpi xs kix wirwmxmzi mrjsvqexmsr, mj xliC Aivi irgvCtxih xlmw AeC."""

#cipherText = re.sub('[^a-z]', '', cipherText.lower()) 

#custom alphabet?
alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9']
alphabet = ''.join(alphabet)

#print str(alphabet)
for i in range (-62,62):
	plainText = []
	print i,":",
	for char in cipherText:
		if char in alphabet:
			index = (alphabet.find(char) + i) % 62
			plainText.append(alphabet[index])
		elif char in ascii_lowercase:
			index = (ascii_lowercase.find(char) + i) % 26
			plainText.append(ascii_lowercase[index])
		elif char in ascii_uppercase:
			index = (ascii_uppercase.find(char) + i) % 26
			plainText.append(ascii_uppercase[index])
		elif char in digits:
			index = (digits.find(char) + i) % 10
			plainText.append(digits[index])
		else:
			plainText.append(char)
	print "".join(plainText)
	key = sys.stdin.readline()

コード例 #51
0
ファイル: ceasar_encode.py プロジェクト: YGeeneY/ceasar
 def _encrypt_letter(self, letter, offset=0):
     position = (alphabet.find(letter) + offset) % self.alpha_len
     return alphabet[position]