by Philfr (1 Submission)
Category: Encryption
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Originally Published: Wed 15th May 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)
simple encryption algorithm
Function RotateLeft(TheString As String, ByVal nbrPlaces As Byte) As String
' Author: Philfr
' Email: [email protected]
' Date: 25 - 5 - 02
' this is a simple encryption algorithm.
' knowing all 'printable' characters are 8 bytes long,
' you can shift the bits to the left and still have a printable character
' to decrypt, all you have to do is to shift them left
' until you have come full circle. ie.
' to Encrypt: RotateLeft(TheString, nbrPlaces)
' to Decrypt: RotateLeft(TheString, 8 - nbrPlaces)
Dim tmp As Integer, i As Integer
Dim mult As Integer, ln As Integer
Dim tmpSt As String
ln = Len(TheString)
tmpSt = ""
nbrPlaces = nbrPlaces Mod 8 ' no point doing more than 7, besides
mult = 2 ^ nbrPlaces ' mult (an Integer) would be too small
For i = 1 To ln
tmp = Asc(Mid$(TheString, i, 1)) ' get ASCII value of each character
tmp = tmp * mult ' apply the multiplier
tmp = tmp Mod 256 + tmp \ 256 ' rotate any "carry" bit
tmpSt = tmpSt & Chr$(tmp) ' add the character to the string
Next i
RotateLeft = tmpSt
End Function