CipherII

By | 2002-06-01

A StreamCipher encryption similar to the first ‘Cipher’ but now it can encrypt any text or binary file.

Original Author: John Cui

Inputs

PlainText(the text to be encrypted/decrypted), Secret(the password)

Assumptions

There is only one function to Encrypt/Decrypt the strings. It is to this point stable that you can encrypt the same string multiple times using different passwords every time and then decrypt in the reverse order.

Returns

Encrypted/Decrypted string

Side Effects

I tested the code in VB6.0 but I mainly used code that’s been part of VB for a while so it should work with ver. 3 and up. One side effect is the cipher speed. It’s still a little slow but I’m working on an 8, 16, and 32 cipher code which would hopefully be fast. Warning!! Keep the strings your working with in memory rather than in an object such as a textbox because there would be loss of data when a string with ascii < 32 is used in a textbox.

API Declarations

Code

Public Function Cipher(PlainText, Secret)
Dim a, b, c
Dim pTb, cTb, cT
For i = 1 To Len(PlainText)
  pseudoi = i Mod Len(Secret)
  If pseudoi = 0 Then pseudoi = 1
  a = Mid(Secret, pseudoi, 1)
  b = Mid(Secret, pseudoi + 1, 1)
  c = Asc(a) Xor Asc(b)
  pTb = Mid(PlainText, i, 1)
  cTb = c Xor Asc(pTb)
  cT = cT + Chr(cTb)
  Form1.Label1.Caption = i
  DoEvents
Next i
EnCipher = cT
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.