2010年3月23日 星期二

解密

有一訊息如下"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個字元)

9 則留言:

  1. Dim a(9) 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, strN
    x = Len(strN) \ 8
    V = 1
    For i = 1 To 8
    For j = 1 To x
    b = Mid(strN, V, 1)
    If b <> "*" Then
    a(j) = a(j) & b
    Else
    a(j) = a(j) & " "
    End If
    V = V + 1
    Next j
    Next i
    For i = 1 To x
    Print #2, a(i);
    Next i
    Close #2
    Close #1
    End Sub

    回覆刪除
  2. 高仔好,
    程式OK, 但是,果然數學上還要再加強,這題數學上的計數上可以讓程式更簡化哦。

    回覆刪除
  3. Tlttgh**thecfit*oon*fnrg*it***negr*asei*
    1,6,11,16,21,26,31,36,41->2,7,12,17,

    y = len(strN)
    x = y/8
    for i =1 to y
    k=1+((i-1)*x mod 40) + ((i-1)*x \40)
    ? #2,mid(strN,k,1);
    next i

    回覆刪除
  4. 忘了加判斷"*"號了。

    回覆刪除
  5. Dim ans As String
    Dim a(10) As String
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Input #1, aa
    cot = Len(aa) / 8
    For j = 0 To 7
    For i = 1 To cot
    c = Mid(aa, i + j * cot, 1)
    If c = "*" Then
    a(i) = a(i) & " "
    Else
    a(i) = a(i) & c
    End If
    Next i
    Next j
    For i = 1 To cot
    ans = ans & a(i)
    Next i
    Close #1
    Open App.Path & "\out.txt" For Output As #1
    Print #2, ans
    Close #1
    End Sub

    回覆刪除
  6. Dim ans As String
    Dim a(10) As String

    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Input #1, aa
    cot = Len(aa) / 8
    For j = 0 To 7
    For i = 1 To cot
    c = Mid(aa, i + j * cot, 1)
    If c = "*" Then
    a(i) = a(i) & " "
    Else
    a(i) = a(i) & c
    End If
    Next i
    Next j
    For i = 1 To cot
    ans = ans & a(i)
    Next i
    Close #1
    Open App.Path & "\out.txt" For Output As #1
    Print #1, ans
    Close #1
    End Sub

    上面有錯,這是改過的...

    回覆刪除
  7. 小白好,
    程式ok。(就錯#1 #2 ,這裡而已嗎?)

    回覆刪除
  8. Dim per(10) As String
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Line Input #1, x
    q = Len(x) \ 8
    j = 1
    Do Until j > q
    b1 = 0
    For i = 1 To 8
    per(j) = per(j) & Mid(x, j + q * b1, 1)
    b1 = b1 + 1
    Next i
    j = j + 1
    Loop
    For i = 1 To q
    ans = ans & per(i)
    ans = Replace(ans, "*", " ")
    Next i
    Print #2, ans
    Close #2
    Close #1
    End Sub

    回覆刪除
  9. Dim a(10) 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, x
    n = Len(x) \ 8
    k = 1
    For i = 1 To 8
    For j = 1 To n
    c = Mid(x, k, 1)
    a(j) = a(j) & c
    k = k + 1
    Next j
    Next i
    For i = 1 To n
    ans = ans & a(i)
    Next i
    Print Replace(ans, "*", " ")
    Close #2
    Close #1
    End Sub

    回覆刪除