Crypt128

Simple small function to Encrypt or Decrypt a string in cell
Simple Encryption function

CodeFunctionName
What is this?

Public

Tested

Imported
Public Function Crypt128(Text)
Dim strTempChar
For i = 1 To Len(Text)
If Asc(Mid$(Text, i, 1)) < 128 Then
strTempChar = Asc(Mid$(Text, i, 1)) + 128
ElseIf Asc(Mid$(Text, i, 1)) > 128 Then
strTempChar = Asc(Mid$(Text, i, 1)) - 128
End If
Mid$(Text, i, 1) = Chr(strTempChar)
Next i
Crypt128 = Text
End Function

' Programmers use encryption and decryption code all the time.
' Some store and retrieve sensitive information, such as passwords and credit card numbers, others simply scramble program settings to ensure users don't start playing around.
' But implementing such functionality into your programs has traditionally been a troublesome feat.
' For a start, you're always messing around with two pieces of code – an encryption function and a decryption function. And then you've got to deal with all the complex string chop-and-change logic within each individual method.
' Then you need to store the information – say, in an INI file. But if you've ever worked with such encryption algorithms, you'll know they often use characters that can't easily be retrieved from such files.
' But with this neat lil' function, all your worries are over. ' Just call Crypt, passing it the text you wish to encode. It will return the encrypted string.
' To decrypt, pass the same function the encrypted string. It will return the decoded text.
' How It Works: The code checks the ASCII value of each character in the passed string.
' If it is below 128, it adds 128 – then converts back to a letter.
' If it is above 128, it subtracts 128 – then converts back to a letter, again.
' If the passed characters has a value of 128, it remains unchanged.
' It does this for each character then passes back the entire encrypted/decrypted string.
' Note: Don’t forget that the encrypted text this code produces is breakable.
' If you're wanting supreme security - alongside keys and such like - to ensure absolutely no-one can access your data, this probably isn't for you. But for basic encryption and decryption, this snippet works wonders.

Text

Usage:
MsgBox Crypt128("Karl Moore") ' -- returns E??? ?ïï??
MsgBox Crypt128("E??? ?ïï??") ' -- returns Karl Moore

Views 4,240

Downloads 1,264

CodeID
DB ID