VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Data Encryption Function.

by David M. Lewis (4 Submissions)
Category: Encryption
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 17th June 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Data Encryption Function.

Rate Data Encryption Function.



'Plaintext Chaining Cipher
'(c) David M. Lewis, 2007, All Rights Reserved.
'[email protected]
'This is another SIMPLE cipher using plaintext chaining.  The key byte is
'pre-altered by the previous byte of plaintext, via xor, before it's applied
'to the next byte of plaintext, via xor.  For added strength we use the
'output to alter the key preminately for the next chunk of data passed to the
'encryption function.  This function is symmetrical.
'
'You are free to use this code for any non-profit purpose.  Please provide me
'with credits in your software, should you use it.


Dim ptloop As Integer 'byte counter
Dim key_byte As Integer 'Decimal (ASCII) value of key byte
Dim pt_byte As Integer 'Decimal value of the plaintext (input) byte
Dim ci_byte As Integer 'Decimal value of the cipher byte (output)
Dim pr_byte As Integer 'Decimal value of the previous plaintext byte.
Dim init_key As Integer 'length of key passed

init_key = Len(key) 'save the length for later.
If init_key > 16 Then MsgBox "Invalid Key Length, Send 16 Bytes.": Exit Function
'^^ Change max key length here.

For ptloop = 1 To Len(pt) 'One byte at a time.
  
  pt_byte = Asc(Mid(pt, ptloop, 1)) 'Grab dec value of pt byte.
  key_byte = Asc(Mid(key, ptloop, 1)) 'Grab dec value of key byte.
  key_byte = key_byte Xor pr_byte ' Chain plaintext to key.
  key = key & Chr(key_byte) ' the chained key is appended to key string.
  ci_byte = pt_byte Xor key_byte ' XOR encrypt pt with key.
  PCC = PCC & Chr(ci_byte) 'Store encrypted/decrypted byte

Next ptloop
 key = Right(key, init_key) 'We're not keeping the original key
End Function

Download this snippet    Add to My Saved Code

Data Encryption Function. Comments

No comments have been posted about Data Encryption Function.. Why not be the first to post a comment about Data Encryption Function..

Post your comment

Subject:
Message:
0/1000 characters