| 09-07-2003, 09:56 AM | #1 |
This is a function package I made that allows to encrypt passwords (such as those in online RPG's) to prevent other people from stealing your password. It seems like you have to register at the site to access it first. Here is the forum adress: http://forum.momm.seiken.co.uk/ The package is here: http://www.seiken.co.uk/cot/cotforum...t=ST&f=7&t=54& |
| 09-07-2003, 11:50 AM | #2 |
Please don't post links without any further explanation, especially not to a site that does not allow to view a single thing without registering. |
| 09-07-2003, 12:05 PM | #3 |
Ops, sorry. Fixed that now. |
| 09-07-2003, 03:36 PM | #4 |
it still requires register.. |
| 09-07-2003, 04:50 PM | #5 |
Post it on these forums! |
| 09-08-2003, 04:21 PM | #6 |
I had certain plans to bring more people to those forums but, oh well. I'm too kind: ^^ Code:
//+----------------------------------------------------------------------------- //| //| File: Password XOR Encryption //| Version: 1.00 //| Date: 2003-09-05 //| Author: Magos (Magnus Östberg) //| Mail: [email][email protected][/email] //| Url: [url]http://www20.brinkster.com/magos818/[/url] //| //| //| Description: //| //| This package contains functions for XOR encryption. It was //| mainly created for string manipulation, which is //| used in password creations for maps. //| //| Place these functions in the "Custom Script Code". To access it, //| click on the top of the tree-list in the Trigger Editor //| (where your map name is written). //| //| NOTE: This package only contains the actual encryption. The //| conversion from Heroes/Items/Stuff to a string (and back again) //| will have to be done by yourself. Why? Well, I have no idea what //| you are going to put into your map ^^. //| //| //| Requirements: //| If you use this package, make sure you've created a global string //| array variable named "CharTable". This should have 70 elements //| (not neccessary since arrays are dynamic), and will contain the //| whole character table after the function SetupTable is run. //| Valid characters in the password string are 0-9, A-Z, a-z, and these //| special characters: ( ) [ ] - _ . and space. //| //| //| How do I do encryption? //| //| The encryption function I provided is a so called XOR-encryption. //| What it does is take a string with the data you would like to save, //| makes a bitwise XOR with a key string (usually the Player's name) //| then you get a password-string. Why XOR with the name? Well, this //| makes the code unique for that player. If one player creates a //| code another player cannot use that code himself. //| No password stealing ^^. //| //| When you create the data string ready to be encrypted, make sure //| you use some characters to be "safety-keys", like the first //| character should always be 'A', the 8th should always be '5', the //| 7th should be like the 3rd + 10 and so on (these are just examples). //| This is to detect faulty passwords and possible bugs. If you don't //| do this kind of test, every possible password could evaluate into //| a 'correct' password. //| //| The GeneratePassword function is used both for generating a //| password and retrieving the data from the password again. //| This is thanks to XOR's nice backwards engineering capabilities. //| //| //| Short explanation please? //| //| 1) On map initialisation, call the function "SetupCharTable": //| //| Custom script: "call SetupCharTable()" //| //| 2) When you want to encrypt a string, call the fucntion //| "GeneratePassword". As parameters you pass the string you wish //| to encrypt and the player's name: //| //| Custom script: "set udg_Code = GeneratePassword(udg_String, udg_Name)" //| //| 3) The value that is returned from "GeneratePassword" is the //| password. Display it to the player so he can write it down. //| //| 4) To get the string back, pass the string and the player's name //| to the "GeneratePassword" function, and the original string //| will be returned. NOTE: It have to be the same name as when //| you encrypted it. //| //| Custom script: "set udg_String = GeneratePassword(udg_Code, udg_Name)" //| //| //| Limits in the functions: //| //| Since not every character in the ASCII table are printable, the //| ASCII table is heavily modified (thus not making it an ASCII table). //| Unluckily the amount of valid characters is not an even 2^n number, //| which is required for a perfect XOR encryption (with typeable //| characters). There are 70 characters, and 64 is the closet number. //| Due to this the function does not encrypt some of the special //| characters. Try to avoid these in your code string. If a player //| name contains any of these characters, the algorithm will still //| work, but won't be as efficient. //| //| //| Function declarations: //| //| void SetupCharTable(void) //| integer BitwiseXOR(integer Value1, integer Value2) //| string GeneratePassword(string Code, string Key) //| //| //| Other info: //| Visit MOMM's clan page for more stuff. //| [url]http://forum.momm.seiken.co.uk/[/url] //| //| //+----------------------------------------------------------------------------- //+----------------------------------------------------------------------------- //| Prepares the char table. Call this function once on map initialization. //| Make sure you have a global string array variable named "CharTable" //| ("udg_CharTable"), otherwise this function will not compile. The size of //| the array should be 70, but that is not important since arrays are dynamic. //+----------------------------------------------------------------------------- function SetupCharTable takes nothing returns nothing //Sets the digits set udg_CharTable[0] = "0" set udg_CharTable[1] = "1" set udg_CharTable[2] = "2" set udg_CharTable[3] = "3" set udg_CharTable[4] = "4" set udg_CharTable[5] = "5" set udg_CharTable[6] = "6" set udg_CharTable[7] = "7" set udg_CharTable[8] = "8" set udg_CharTable[9] = "9" //Sets the capital letters set udg_CharTable[10] = "A" set udg_CharTable[11] = "B" set udg_CharTable[12] = "C" set udg_CharTable[13] = "D" set udg_CharTable[14] = "E" set udg_CharTable[15] = "F" set udg_CharTable[16] = "G" set udg_CharTable[17] = "H" set udg_CharTable[18] = "I" set udg_CharTable[19] = "J" set udg_CharTable[20] = "K" set udg_CharTable[21] = "L" set udg_CharTable[22] = "M" set udg_CharTable[23] = "N" set udg_CharTable[24] = "O" set udg_CharTable[25] = "P" set udg_CharTable[26] = "Q" set udg_CharTable[27] = "R" set udg_CharTable[28] = "S" set udg_CharTable[29] = "T" set udg_CharTable[30] = "U" set udg_CharTable[31] = "V" set udg_CharTable[32] = "W" set udg_CharTable[33] = "X" set udg_CharTable[34] = "Y" set udg_CharTable[35] = "Z" //Sets the small letters set udg_CharTable[36] = "a" set udg_CharTable[37] = "b" set udg_CharTable[38] = "c" set udg_CharTable[39] = "d" set udg_CharTable[40] = "e" set udg_CharTable[41] = "f" set udg_CharTable[42] = "g" set udg_CharTable[43] = "h" set udg_CharTable[44] = "i" set udg_CharTable[45] = "j" set udg_CharTable[46] = "k" set udg_CharTable[47] = "l" set udg_CharTable[48] = "m" set udg_CharTable[49] = "n" set udg_CharTable[50] = "o" set udg_CharTable[51] = "p" set udg_CharTable[52] = "q" set udg_CharTable[53] = "r" set udg_CharTable[54] = "s" set udg_CharTable[55] = "t" set udg_CharTable[56] = "u" set udg_CharTable[57] = "v" set udg_CharTable[58] = "w" set udg_CharTable[59] = "x" set udg_CharTable[60] = "y" set udg_CharTable[61] = "z" //Sets the special characters set udg_CharTable[62] = "(" set udg_CharTable[63] = ")" //Sets the special characters //(These will NOT be encrypted) set udg_CharTable[64] = "." set udg_CharTable[65] = "-" set udg_CharTable[66] = "_" set udg_CharTable[67] = "[" set udg_CharTable[68] = "]" set udg_CharTable[69] = " " endfunction //+----------------------------------------------------------------------------- //| Does a bitwise XOR on two integer values //+----------------------------------------------------------------------------- function BitwiseXOR takes integer Value1, integer Value2 returns integer local integer Index local integer ResultValue local integer array Byte1 local integer array Byte2 local integer array ResultByte //Convert Value1 to a Byte set Index = 8 loop set Index = Index - 1 set Byte1[Index] = ModuloInteger(Value1, 2) set Value1 = Value1 / 2 exitwhen Index <= 0 endloop //Convert Value2 to a Byte set Index = 8 loop set Index = Index - 1 set Byte2[Index] = ModuloInteger(Value2, 2) set Value2 = Value2 / 2 exitwhen Index <= 0 endloop //Makes a bitwise XOR on the Bytes set Index = 0 loop if (Byte1[Index] == Byte2[Index]) then set ResultByte[Index] = 0 else set ResultByte[Index] = 1 endif set Index = Index + 1 exitwhen Index >= 8 endloop //Convert the resulting Byte back to an integer set Index = 0 set ResultValue = 0 loop set ResultValue = ResultValue * 2 set ResultValue = ResultValue + ResultByte[Index] set Index = Index + 1 exitwhen Index >= 8 endloop return ResultValue endfunction //+----------------------------------------------------------------------------- //| Takes a string and uses the key (usually a player's name) to encrypt it. //| To get the original string back, call the function with that string and //| the same key used in the encryption. //+----------------------------------------------------------------------------- function GeneratePassword takes string Code, string Key returns string local integer Index = 0 local integer KeyIndex = 0 local integer KeyLength = 0 local integer CurrentValue = 0 local integer CurrentKeyValue = 0 local string CurrentCharacter = "" local string CurrentKeyCharacter = "" local string ResultCode = "" //Calculates the length of the Key loop exitwhen SubStringBJ(Key, KeyLength + 1, KeyLength + 1) == "" set KeyLength = KeyLength + 1 endloop //Abort if the key length is 0 (to avoid crashes) if KeyLength <= 0 then return "" endif //Loop through every character in the string and encrypt it loop //Get a character from the code set CurrentCharacter = SubStringBJ(Code, Index + 1, Index + 1) //Exit when the end of the code string is reached exitwhen CurrentCharacter == "" //Converts a character to a value //Traverses the character table until the character is found set CurrentValue = 0 loop exitwhen udg_CharTable[CurrentValue] == CurrentCharacter set CurrentValue = CurrentValue + 1 //If the character is not found, set it to 0 if CurrentValue >= 70 then set CurrentValue = 0 exitwhen true endif endloop //Get a proper key index set KeyIndex = ModuloInteger(Index, KeyLength) //Get a character from the key set CurrentKeyCharacter = SubStringBJ(Key, KeyIndex + 1, KeyIndex + 1) //Converts a character to a value //Traverses the character table until the character is found set CurrentKeyValue = 0 loop exitwhen udg_CharTable[CurrentKeyValue] == CurrentKeyCharacter set CurrentKeyValue = CurrentKeyValue + 1 //If the character is not found, set it to 0 if CurrentKeyValue >= 70 then set CurrentKeyValue = 0 exitwhen true endif endloop //Make sure only a valid character is encrypted if ((CurrentKeyValue < 0) or (CurrentKeyValue >= 64)) then set CurrentKeyValue = 0 endif //Encrypt the character using XOR set CurrentValue = BitwiseXOR(CurrentValue, CurrentKeyValue) //Convert the value to a character set CurrentCharacter = udg_CharTable[CurrentValue] //Add the character to the resulting code string set ResultCode = ResultCode + CurrentCharacter set Index = Index + 1 endloop return ResultCode endfunction |
| 09-08-2003, 04:22 PM | #7 |
In the actual manipulation of your string, these functions may come in handy: Code:
//+-----------------------------------------------------------------------------
//| Converts a character to an integer value (ASCII)
//+-----------------------------------------------------------------------------
function ConvertCharToInt takes string Character returns integer
local integer Index = 0
//Traverses the ASCII table until the character is found.
loop
exitwhen udg_CharTable[Index] == Character
set Index = Index + 1
//If the character is not found, return 0
if Index >= 70 then
set Index = 0
exitwhen true
endif
endloop
return Index
endfunctionCode:
//+----------------------------------------------------------------------------- //| Converts an integer value (ASCII) to a character //+----------------------------------------------------------------------------- function ConvertIntToChar takes integer Value returns string return udg_CharTable[Value] endfunction |
