Vb EncryptFile

2010-03-24 1:43 am
EncryptFile.TXT
The data is stored in the same format as the
CommaFile.TXT file. However, the data
has been encrypted. You must decrypt the
data.
Every odd numbered character (1,3,5,...) has had its ASCII value increased by 1.
(So the letter 'd' has become 'e')
Every even numbered character (0,2,4,6,...) has had its ASCII value decreased by 1.
(So the letter 'h' has become 'g')
Example: The 1st row above begins with Spl. When decrypted, this becomes Tom.

example text file(EncryptFile.TXT):
Spl !Lprcx-485:18w-04+25/4-03
SsdwnsGnsruds+66:2455+20-4-4/4

how to read the text from this Textfile and write to other textfile(FinalFile.text) that follow the format below:
1. Each string must be surrounded by double quotes.
Each piece of data must be delimited by a Tab
Each person's data must be stored an a new line

2. The data to be stored is:
Person ID
Person Name
Total Score (addition of all three scores for the person)
更新1:

how to determine which function are the system going to use? Use If statement to check? or not? and what is the code for checking this?

回答 (1)

2010-03-24 4:31 pm
✔ 最佳答案
Public Function Decrypt(ByVal someString As String) As String
Dim Pass As String
Dim Temp As Integer, i As Integer

For i = 1 To Len(someString)
Temp = Asc(Mid(someString, i, 1))
If i Mod 2 = 0 Then
Temp = Temp - 1
Else
Temp = Temp + 1
End If
Pass = Pass & Chr(Temp)
Next i
Decrypt = Pass
End Function

Public Function Encrypt(ByVal someString As String) As String
Dim Pass As String
Dim Temp As Integer, i As Integer

For i = 1 To Len(someString)
' Get the ASCII value of each character.
Temp = Asc(Mid(someString, i, 1))
' Shift up or down according to odd or even position.
If i Mod 2 = 0 Then
Temp = Temp + 1
Else
Temp = Temp - 1
End If
Temp = Temp
' Convert ASCII value to character.
Pass = Pass & Chr(Temp)
Next i
Encrypt = Pass
End Function

2010-03-25 01:40:34 補充:
realname = Decrypt("Ssdwns")

realname is Trevor


收錄日期: 2021-04-25 20:33:36
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20100323000051KK01050

檢視 Wayback Machine 備份