Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to create a simple encryption utility using VB 6. The form has 2 displays so that when I open a file it is displayed normally in one list box and it's ascii equivalent in the other. I open the file (list of items) and they appear as they should but with just the first ascii value for the first letter of each item in the list. I realise that this is how Asc command deals with this situation but I require the ascii values for the entire string to be displayed.
Could someone please give me an example of the coding I should be using to complete my task. Thank youRegards
M

You apply the Asc function to each character in the string inside a For/next loop using the Mid$ function.
StrLen = len(YourString)
For a = 1 to Strlen
AscChr = mid$(YourString, a,1)
next
Stuart

I have declared the whole file content as the string "FileName" as this is what the user enters prior to opening the file to be encrypted. Bear with me as I am new to this VB.
Do I have to declare StrLen As Integer or will VB recognise StrLen as it is.Thank you for your reply
M

we just did this in a programming class
heres dencryption -
Public Function DecryptStr(ByRef strIn As String, strPwd As String) As String
Dim strPass As String, strPass2 As String, intPass As Integer, intPass2 As Integer, intT As Integer
Dim intCountPass As Integer
For intCount = 1 To Len(strIn)
intCountPass = intCountPass + 1
If intCountPass > Len(strPwd) Then
intCountPass = 1
End If
strPass = Mid(strPwd, intCountPass, 1)
strPass2 = Mid(strIn, intCount, 1)
intPass = Asc(strPass)
intPass2 = Asc(strPass2)
intT = intPass2 - intPass
If intT < 0 Then
strIn = strIn & Chr(intT + 128)
End If
Next intCount
DecryptStr = strIn
End Function
and encryption-
Public Function EncryptStr(ByRef strIn As String, strPwd As String) As String
Dim intCountPass As Integer
Dim strPass As String, strPass2 As String, intPass As Integer, intPass2 As Integer, intT As Integer
For intCount = 1 To Len(strIn)
'assign letter of password asci value
intCountPass = intCountPass + 1
If intCountPass > Len(strPwd) Then
intCountPass = 1
End If
strPass = Mid(strPwd, intCountPass, 1)
strPass2 = Mid(strIn, intCount, 1)
intPass = Asc(strPass)
intPass2 = Asc(strPass2)
intT = intPass + intPass2
strIn = strIn & Chr(intT Mod 128)
Next intCount
EncryptStr = strIn
End Function1.4 amd
pos mobo
2 gigs ddr
2 21inch montiors
radeon 9700 proand one of those rubber, keyboards that you can roll into a ball

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |