VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



SKC Encryption Function

by David M. Lewis (4 Submissions)
Category: Encryption
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Sun 28th May 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

SKC Encryption Function

Rate SKC Encryption Function



'(c) David M. Lewis, 2006, All Rights Reserved.
'[email protected]
'This is a simple XOR cipher using a key shuffle to alter the key sequence
'as each byte is encrypted.
'The last input byte (plaintext) determines how the key string is shuffled.
'This is a 128 bit cipher but you can easily expand the key length.
'Beware that the key length will eventually exceed the length of the input,
'so watch out for the string length limitation when passing large blocks of
'plaintext (pt).
'Dmode TRUE = decryption.
'Dmode FALSE = encryption
'This is offered freely and may ONLY be used for any NON-PROFIT purposes.
'Please give my credits, if you use it in your program.

Dim ptloop As Integer 'Iteration count
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 shuff_byte As Integer 'Decimal value of the shuffle.


If Len(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.  Stream cipher.
  
  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.
   
  ci_byte = pt_byte Xor key_byte ' XOR encrypt pt with key.
  
  If dmode = False Then shuff_byte = pt_byte 'Encrypting mode..
  If dmode = True Then shuff_byte = ci_byte ' Decrypting mode..
   
  'Now we shuffle.  Actually we pick a byte and then append it to the key
  
  shuff_byte = shuff_byte Mod Len(key) + 1 'Pick one based on plaintext
  key = key & Mid(key, shuff_byte, 1) 'Append it to the key stream.
         
  SKC = SKC & Chr(ci_byte) 'Store encrypted/decrypted byte

Next ptloop
 key = "" 'clear entire key
End Function


Download this snippet    Add to My Saved Code

SKC Encryption Function Comments

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

Post your comment

Subject:
Message:
0/1000 characters