暗号化:python
まだ途中やけどとりあえず挙げます。
作りたかったのはこんな感じ。秘密鍵で打った文章が暗号化されて出てくるのをイメージしてたけど今日は間に合わず。
import re print("秘密鍵を英語で10文字以上で入力してください") secret_code = input() #try: is_code_regex = re.compile(r"[a-z]+", re.I) #except Exception: # print("文字数が足りません") mo = is_code_regex.findall(secret_code) mo_join = "".join(mo).lower() code_dict = {"a": "A", "b": "B", "c": "C", "d": "D", "e": "E", "f": "F", "g": "G", "h": "H", "i": "I", "j": "J", "k": "K", "l": "L", "m": "M", "n": "N", "o": "O", "p": "P", "q": "Q", "r": "R", "s": "S", "t": "T", "u": "U", "v": "V", "w": "W", "x": "X", "y": "Y", "z": "Z"} alphabet_list = ["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"] iterator_alphabet = iter(alphabet_list) try: for i in mo_join: code_dict[i] = next(iterator_alphabet) except StopIteration: print(code_dict)
初めて触ったのは例外処理とイテレーター。そういやsub()メソッドを学んでやってみたくなったコードやけど結局使ってない。
どっかで入れよう。