Created
March 19, 2019 05:10
-
-
Save lidopypy/e6b503fe5da6df50a7feb17cbbb1274b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def chrshift_function(num=None,list=[]):\n", | |
" num = num\n", | |
" list = list\n", | |
" Eng_list = 'abcdefghijklmnopqrstuvwxyz'\n", | |
" #做字典轉換\n", | |
" chr2num = { i:chr for chr,i in enumerate(Eng_list)}\n", | |
" num2chr = { chr:i for chr,i in enumerate(Eng_list)}\n", | |
" for i in range(num):\n", | |
" num2chr[26+int(i)]=num2chr[i]\n", | |
" \n", | |
" #將list轉成num\n", | |
" num_list = []\n", | |
" for i in list:\n", | |
" if i in chr2num:\n", | |
" num_list.append(str(chr2num.get(i)+num))\n", | |
" else :\n", | |
" num_list.append(i)\n", | |
" \n", | |
" #將num_list shift num個字再轉成answer\n", | |
" answer = []\n", | |
" for i in num_list:\n", | |
" try:\n", | |
" if int(i) in num2chr:\n", | |
" answer.append(num2chr.get(int(i)))\n", | |
" else:\n", | |
" answer.append(i)\n", | |
" except:\n", | |
" answer.append(i) \n", | |
" for j in answer:\n", | |
" print(j, end=\"\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url." | |
] | |
} | |
], | |
"source": [ | |
"list = '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.'\n", | |
"chrshift_function(num = 2,list = list)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.6" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment