Skip to content

Commit 4b38fbb

Browse files
Merge pull request #68 from cdlab-sit/octan
8の解答追加
2 parents ae951d3 + 145097f commit 4b38fbb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

octan/08.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 与えられた文字列の各文字を,以下の仕様で変換する関数cipherを実装せよ.
2+
# *英小文字ならば(219 - 文字コード)の文字に置換
3+
# *その他の文字はそのまま出力
4+
# この関数を用い,英語のメッセージを暗号化・復号化せよ.
5+
6+
7+
def cipher(line):
8+
ci_line = ""
9+
for char in line:
10+
if 96 < ord(char) < 123:
11+
char = chr(219 - ord(char))
12+
ci_line += char
13+
return ci_line
14+
15+
string = "abCdeFいろは"
16+
print("変化前: ", string)
17+
string = cipher(string)
18+
print("暗号化: ", string)
19+
string = cipher(string)
20+
print("復号化: ", string)

octan/09.py

Whitespace-only changes.

0 commit comments

Comments
 (0)