Problem 7 (密碼解密 8%)
在密碼學裡面有一種很簡單的加密方式,就是把原始資料的每個字元通通加上某一個整數K而得到密碼的字元(原始資料及密碼字元一定都在ASCII碼中可列印的範圍內)。例如若K=2,那麼apple經過加密後就變成crrng了;解密則是反過來做。
輸入說明:第一列為加密的K值,第二列為要解密的列數,第三列及以後就是需要解密的字串。(請參照輸入範例)
輸入範例:test7.txt
7
3
1JKJ'pz'{ol'{yhklthyr'vm'{ol'Jvu{yvs'Kh{h'Jvywvyh{pvu5
1PIT'pz'h'{yhklthyr'vm'{ol'Pu{lyuh{pvuhs'I|zpulzz'Thjopul'Jvywvyh{pvu5
1KLJ'pz'{ol'{yhklthyr'vm'{ol'Kpnp{hs'Lx|pwtlu{'Jvywvyh{pvu5
輸出說明:對每一測試資料,請輸出解密後的原始資料。(請參照輸出範例)
輸出範例:result7.txt
*CDC is the trademark of the Control Data Corporation.
*IBM is a trademark of the International Business Machine Corporation.
*DEC is the trademark of the Digital Equipment Corporation.
今天早上把96正式歷屆作完囉 :)
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, a
Input #1, b
Do While Not EOF(1)
Line Input #1, x
Call A1(x, a)
Loop
Close
Close
End
End Sub
Sub A1(x, a)
For i = 1 To Len(x)
m = Mid(x, i, 1)
nx = nx & Chr(Asc(m) - a)
Next
Print #2, nx
End Sub
今天早上寫蠻快的 吃午飯去:)
Private Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, K
Input #1, N
For i = 1 To N
ans = ""
Line Input #1, X
For j = 1 To Len(X)
ans = ans & Chr(Asc(Mid(X, j, 1)) - K)
Next j
Print #2, ans
Next i
Close #2
Close #1
End
End Sub