ENCRYPTION DEMO AND DLL

© 2003, David Drake

Liberated Code Foundry:

Website

Home

Collision Simulator

Foon's Tips

Encryption

Lesson Browser

Cookie DLL

LB NoteBoard

LB Clipboard Commands

Clipboard API Demos

Compiled HTML Help

Tabstrip

Tabstrip Demo

Scrolling Controls

Why API?

Sprite in a Box

Newsletter Help

Index

Encryption using Liberty BASIC

Encrytion using cryptor.dll

Simple Encryption

David Drake has provided two methods of encryption. The first method is "all Liberty BASIC." It uses native Liberty BASIC commands to encrypt data such as game scores so that it is not easily modified by a user. This level of encryption would be easy to break and is meant to keep data safe for non-critcal uses. It would keep casual users from modifying their game scores or save-info, for instance. To use it, you don't even need to understand how it works. David has provided two functions - one to encrypt and the other to decrypt. Just paste the functions into your program and call them as needed.

XOR

The encryption method depends upon the XOR operator. There will be a key character (or a string of characters.) Each character to be encrypted is put together with the key character using the XOR bitwise operator. The resulting encrypted character is then saved. When the encrypted character is put together with the key in an identical XOR operation, the original data character is restored.

Cryptor DLL

For more secure encryption, David has written a free DLL called cryptor.dll. The DLL, DLL source in both BCX and C syntax, and the Liberty BASIC demo are included with the zip archive for this newsletter. Thanks, David!


input "Enter score to encrypt > ";score$
print "OK, let's encrypt ";score$
print

gosub [writeScoreFile]
print "Encrypted score is ";encryptedScore$

gosub [readScoreFile]
print "Unencrypted score is ";scoreRead$
end

[writeScoreFile]
encryptedScore$ = ""
open "score.txt" for output as #score
for a = 1 to len(score$)
encryptedScore$ = encryptedScore$+chr$(asc(mid$(score$,a,1)) xor 22)
next a
#score, encryptedScore$;
close #score
return

[readScoreFile]
scoreRead$ = ""
open "score.txt" for input as #score
line input #score, fileScore$
close #score

for a = 1 to len(fileScore$)
scoreRead$ = scoreRead$+chr$(22 xor asc(mid$(fileScore$,a,1)))
next a
return


'############################################
'# Cryptor.dll demo                         #
'# Cryptor.dll by David Drake               #
'# Released as open-source August, 2002     #
'# Use at your own risk                     #
'#                                          #
'# This DLL produces a very low-level       #
'# encryption using character XOR functions.#
'# Thus, longer encryption keys produce     #
'# stronger encryption.  This would work    #
'# well for encrypting game data, etc.      #
'#                                          #
'# Cryptor.dll is a 32-bit DLL created with #
'# the help of BCX and LCC-WIN32, so it     #
'# is pretty fast.  On my 800MHz machine,   #
'# with a 10-character encryption key,      #
'# crypter.dll will process a 1MB file in   #
'# about five seconds.                      #
'#                                          #
'#                                          #
'# DLL package includes                     #
'# cryptor.dll - 32-bit dll                 #
'# cryptor.bas - BCX source code for DLL    #
'# cryptor.c   - C source code for DLL      #
'# cryptor_demo.bas - This file written for #
'#               Liberty BASIC 3.01         #
'############################################


'############################################
'# Meat of the program begins here          #
'#                                          #
'# function call:                           #
'# RESULT = ENCRYPTION(MODE,INFILE$,OUTFILE$,KEY$)
'#                                          #
'# dll call:                                #
'# calldll #en, "_ENCRYPT",_  **You must use the underscore before ENCRYPT**
'#            MODE as SHORT,_               #
'#            INFILE$ as PTR,_              #
'#            OUTFILE$ as PTR,_             #
'#            KEY$ as PTR,_                 #
'#            RESULT as SHORT               #
'#                                          #
'# The ENCRYPTION function calls the dll    #
'# MODE = 1: Encrypt source file and write  #
'#           to the destination file        #
'#                                          #
'# MODE = 2: Decrypt the source file and    #
'#           write to the destination file  #
'#                                          #
'# INFILE$:  The file spec for the source   #
'#           file                           #
'#                                          #
'# OUTFILE$: The file spec for the destin-  #
'#           ation file                     #
'#                                          #
'# KEY$:     A string of any length used to #
'#           encrypt the file               #
'#                                          #
'# Result codes:                            #
'#   1 = De/Encryption successful           #
'#   2 = Invalid MODE value (not 1 or 2)    #
'#   3 = Source file does not exist         #
'#   4 = Destination file already exists    #
'############################################


Home

Collision Simulator

Foon's Tips

Encryption

Lesson Browser

Cookie DLL

LB NoteBoard

LB Clipboard Commands

Clipboard API Demos

Compiled HTML Help

Tabstrip

Tabstrip Demo

Scrolling Controls

Why API?

Sprite in a Box

Newsletter Help

Index