computer code | 電腦程式碼 | Diànnǎo chéngshì mǎ |
secret | 秘密 | mìmì |
code | 程式碼 | chéngshì mǎ |
encode | 編碼 | biānmǎ |
decode | 解碼 | jiěmǎ |
message | 訊息 | xùnxí |
spy | 間諜 | Jiàndié |
mission | 使命 | Shǐmìng |
You are a spy. You have a secret mission. You have a message:
The target is wkxq, the key is 14.
Who is the target? We have to save them. The target’s name is encoded.
We have a way to decode messages. First put the key in the middle of the circle. Look at what happens when we make the key higher or lower. Then to DECODE the message find the gray letter that matches our message. Then the blue or purple letter that is touching the gray letter is the decoded letter.

Let’s try encoding and decoding. First pick a number between 5 and 20.
Write this on your paper: key:_______
Write your name on your paper. To encode your name you need to find the blue and purple letters that match your name. Then the gray letters that touch the blue and purple letters are encoded.
Now fold your paper so that only you can only see the key and the encoded message.
Ok, now that we have tried to encode and decode, let’s try to write some code to do it for us.
We’re going to follow this lesson.
https://www.junyiacademy.org/article/7b3df2aa6ba345e3a0dbacbf56807476
This is a link to a python interpreter.
commands | 命令 | Mìnglìng |
列印 | Liè yìn | |
name = ‘Kyle’ print(‘this is my name: ‘,name) | this is my name: kyle | |
input | 輸入 | shūrù |
name = input(‘please enter your name: ‘) | ||
find | 尋找 | xúnzhǎo |
name = ‘Kyle’ position = name.find(‘K’) print(position) | 0 | |
% modulo | % 模除 | Mó shù |
integer | int() | 整數 | Zhěngshù |
number = 14 print (int(number) +1 | 15 | |
for loop | for 迴圈 | For huí quān |
for each letter in the word do this | 對單字中的每個字母都執行此操作 | Duì dānzì zhōng de měi gè zìmǔ dōu zhíxíng cǐ cāozuò |
word = ‘Kyle’ for letter in word: print(letter) | K y l e |
variables | 變數 | biànshù |
alphabet = abcdefghijklmnopqrstuvwxyz | 字母 | Zìmǔ |
key | 鑰匙 | yàoshi |
position | 位置 | wèizhì |
message | 訊息 | xùnxí |
letter | 字母 | Zìmǔ |
new | 新的 | xīn de |
camel case / camelCase | 駝峰式命名法 | Tuófēng shì mìngmíng fǎ |

please enter an English letter: | 請輸入英文訊息: | qǐng shūrù yīngwén xùnxí: |
the new letter is: | 新信件是: | Xīn xìnjiàn shì: |
enter “e” for encode or “d” for decode: | 輸入“e”進行編碼或輸入“d”進行解碼: | Shūrù “e” jìnxíng biānmǎ huò shūrù “d” jìnxíng jiěmǎ: |
please input the message: | 請輸入留言內容: | qǐng shūrù liúyán nèiróng: |
please enter the key: | 請輸入密鑰: | Qǐng shūrù mì yào: |
% 模除(英語:modulo 有時也稱作 modulus),又稱模數、取模、取模運算等,它得出一個數除以另一個數的餘數。給定兩個正數:被除數 和除數
,
(通常縮寫為
),得到的是使用歐幾里得除法時的餘數。
所得之數被稱為
的小數部份。
舉個例子:計算表達式 得到
,因為
的商為
而餘數為
;而
得到
,因為
的商為
而餘數為
;
Example code:
doWhat = input(‘enter “e” for encode or “d” for decode’)
key = input(‘please enter the key:’) % 26
if doWhat == “d” :
key = 26 – int(key)
message = input(‘please input the message:’)
newMessage = ”
alphabet = ‘abcdefghijklmnopqrstuvwxyz’
for char in message:
tempChar = char
position = alphabet.find(char)
#print (position)
newPosition = (int(position) + int(key))%26
newChar = alphabet[newPosition]
newMessage += newChar
print(newMessage)