在密碼學裡面有一種很簡單的加密方式,就是把原始資料的每個字元通通加上某一個整數K而得到密碼的字元(原始資料及密碼字元一定都在ASCII碼中可列印的範圍內)。例如若K=2,那麼apple經過加密後就變成crrng了;解密則是反過來做。
輸入說明:第一列為加密的K值,第二列為要解密的列數,第三列及以後就是需要解密的字串。(請參照輸入範例)
輸入範例:in.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
輸出說明:對每一測試資料,請輸出解密後的原始資料。(請參照輸出範例)
輸出範例:out.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.
Dim key, times As Integer
回覆刪除Dim strr(999), ok As String
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, key
Input #1, times
countt = 0
Do
Line Input #1, strr(countt)
countt = countt + 1
Loop Until EOF(1)
countt = countt - 1
For i = 0 To countt
For ii = 1 To Len(strr(i))
ok = ok & Chr((Asc(Mid(strr(i), ii, 1)) - key))
Next
strr(i) = ok
ok = ""
Next
For showw = 0 To countt
Print #2, strr(showw)
Next
Close #2
Close #1
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, p
For i = 1 To p
Line Input #1, x
y = Len(x)
For j = y To 1 Step -1
a = Mid(x, j, 1)
w = Asc(a)
w = w - k
ans = Chr(w) & ans
Next
Print #2, ans
ans = ""
Next
Close #2
Close #1
End
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
Line Input #1, x
m = ""
For j = 1 To Len(x)
m = m & Chr(Asc(Mid(x, j, 1)) - k)
Next
Print #2, m
Next
Close
Close
End
End Sub
程式正確
回覆刪除