2012年11月20日 星期二

解密

有一訊息如下"The final contest for getting right"
經放置於8*10的陣列中為
The*fina
l*contes
t*for*ge
tting*ri
ght*****
此列之後的資料皆為空白
加密後的資料為"Tlttgh**thecfit*oon*fnrg*it***negr*asei*"
寫一程式可以將加密過的訊息解密(訊息長度不超過80個字元)

2 則留言:

  1. Dim strr, ok As String
    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, strr
    For i = 1 To 5
    ok = ok & Mid(strr, i, 1)
    For ii = 1 To 7
    ok = ok & Mid(strr, i + ii * 5, 1)
    Next
    Next
    ok = Replace(ok, "*", " ")
    Print #2, ok
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim str(8, 5) As String
    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, n
    n = Replace(n, "*", " ")
    For i = 1 To 8
    For j = 1 To 5
    str(i, j) = Mid(n, 5 * (i - 1) + j, 1)
    Next
    Next
    For i = 1 To 5
    For j = 1 To 8
    Print #2, str(j, i);
    Next
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除