Hey Matt,
Thanks for the quick reply!
The code is below (apoogies for the length), but the questions is simply
whether the encrypt() and decrypt() functions are the same in Adobe CF
and OpenBD?
-----------------------------------------------------------------------------------
<cfsilent>
<!--- -->
TAG: crypt.cfm (cf_crypt)
AUTHOR: Bill Killillay ([email protected])
LICENSE:
OSI Certified Open Source Software - see included license.txt
DESCRIPTION:
See the included readme.txt for full description and use
instructions.
USAGE:
See the included readme.txt for full usage and notes.
REVISION HISTORY: v 1.0 Aug 15, 2001
Original Release
REVISION HISTORY: v 1.5 Nov 25, 2001 Rewrote
in CFScript, finally
REVISION HISTORY: v 1.5.1 Nov 28, 2001 Fixed a
couple of small errors
REVISION HISTORY: v 2.0 Jan 29, 2001 Changed
a couple of things
--->
<cfscript>
doLogic = "False";
if (not isDefined('attributes.action')) {
attributes.action = "en";
}
if (not isDefined('attributes.return')) {
attributes.return = "crypt";
}
setvariable("caller.#attributes.return#",structnew());
setvariable("caller.#attributes.return#.value","");
setvariable("caller.#attributes.return#.error", "False");
if (not isDefined('attributes.string') or not
len(trim(attributes.string))) {
errorMsg = "String is a required element!";
setvariable("caller.#attributes.return#.value",errorMsg);
setvariable("caller.#attributes.return#.error", "True");
doLogic = "False";
break;
} else {
string = attributes.string;
setvariable("caller.#attributes.return#.string",
string);
doLogic = "True";
}
if (not isDefined('attributes.key') or not
len(trim(attributes.key)))
{
errorMsg = "Key is a required element!";
setvariable("caller.#attributes.return#.value",errorMsg);
setvariable("caller.#attributes.return#.error", "True");
doLogic = "False";
break;
} else {
key = attributes.key;
setvariable("caller.#attributes.return#.key",key);
doLogic = "True";
}
if (doLogic eq "True") {
switch(attributes.action) {
// Do our encryption stuff here.
case("en"):
stringCheckSum = 0;
thisCharVal = 0;
loopCnt = len(string);
for (cnt = 1; cnt lte loopCnt; cnt =
cnt + 1) {
thisCharVal = asc(mid(string,
cnt, 1));
stringCheckSum = stringCheckSum
+ thisCharVal;
}
if (len(stringCheckSum) mod 2 is 1) {
stringCheckSum = "0" &
stringCheckSum;
}
halfLen = len(stringCheckSum) \ 2;
stringCheckSum = mid(stringCheckSum,
halfLen + 1, halfLen) &
mid(stringCheckSum, 1, halfLen);
stringRaw = encrypt(string, key);
stringClean = "";
loopCnt = len(stringRaw);
for (cnt = 1; cnt lte loopCnt; cnt =
cnt + 1) {
thisCharHex =
formatbasen(bitshln(asc(mid(stringRaw, cnt, 1)), 1),
16);
if (len(thisCharHex) eq 1) {
thisCharHex = "0" &
thisCharHex;
}
thisCharHexFlip =
mid(thisCharHex,2,1) & mid(thisCharHex,1,1);
stringClean = stringClean &
ucase(thisCharHexFlip);
}
// Create the return variable with
encrypted text and original
checksum.
value = stringCheckSum & "J" &
stringClean; // The "J" is a
non-obvious delimiter (and the first letter of my wifes name)
setvariable("caller.#attributes.return#.value", value);
break;
// This is our break between case statements //
// just some space for me to catch my breath //
// Do our decryption stuff here.
case("de"):
crypErrArry = arrayNew(1);
if (findnocase("J", string, 1) is 0) {
arrayAppend(crypErrArry, "No
Check Sum");
if (arraylen(crypErrArry) gte
1) {
errorMsg = "";
loopCnt =
arraylen(crypErrArry);
for (cnt = 1; cnt lte
loopCnt; cnt = cnt + 1) {
errorMsg =
errorMsg & crypErrArry[1];
}
setvariable("caller.#attributes.return#.error", "true");
setvariable("caller.#attributes.return#.errorType", errorMsg);
}
break;
}
if (findnocase("J", string, 1) gte 1) {
stringCheckSum = mid(string, 1,
(findnocase("J", string, 1) -1));
halfLen = len(stringCheckSum)/
2;
stringCheckSum =
mid(stringCheckSum, halfLen + 1, halfLen) &
mid(stringCheckSum, 1, halfLen);
stringClean = right(string,
len(string) - findnocase("J", string,
1));
}
if (len(stringClean) is 0 or
(len(stringClean) mod 2 is not 0)) {
arrayAppend(crypErrArry, "Bad
string.");
if (arraylen(crypErrArry) gte
1) {
errorMsg = "";
loopCnt =
arraylen(crypErrArry);
for (cnt = 1; cnt lte
loopCnt; cnt = cnt + 1) {
errorMsg =
errorMsg & crypErrArry[1];
}
setvariable("caller.#attributes.return#.error", "true");
setvariable("caller.#attributes.return#.errorType", errorMsg);
}
break;
}
stringRaw="";
loopCnt = len(stringClean);
for (cnt = 1; cnt lte loopCnt; cnt =
cnt + 2) {
thisCharHexFlip =
mid(stringClean, cnt, 2);
thisCharHex =
mid(thisCharHexFlip, 2, 1) & mid(thisCharHexFlip, 1,
1);
thisChar =
chr(bitshrn(inputbasen(thisCharHex, 16), 1));
stringRaw = stringRaw &
thisChar;
}
original = decrypt(stringRaw, key);
originalCheckSum = 0;
loopCnt = len(original);
for (cnt = 1; cnt lte loopCnt; cnt =
cnt + 1) {
thisCharVal = asc(mid(original,
cnt, 1));
originalCheckSum =
originalCheckSum + thisCharVal;
}
if (originalCheckSum neq
stringCheckSum) {
arrayAppend(crypErrArry, "Check
sum failed!");
if (arraylen(crypErrArry) gte
1) {
errorMsg = "";
loopCnt =
arraylen(crypErrArry);
for (cnt = 1; cnt lte
loopCnt; cnt = cnt + 1) {
errorMsg =
errorMsg & crypErrArry[1];
}
setvariable("caller.#attributes.return#.error", "true");
setvariable("caller.#attributes.return#.errorType", errorMsg);
}
break;
}
// Setup our return variable now
setvariable("caller.#attributes.return#.value", original);
break;
}
}
</cfscript>
</cfsilent>
----------------------------------------------------------------------------------
Bryan Stevenson B.Comm.
VP & Director of E-Commerce Development
Electric Edge Systems Group Inc.
phone: 250.480.0642
fax: 250.480.1264
cell: 250.920.8830
e-mail: [email protected]
web: www.electricedgesystems.com
Notice:
This message, including any attachments, is confidential and may contain
information that is privileged or exempt from disclosure. It is intended
only for the person to whom it is addressed unless expressly authorized
otherwise by the sender. If you are not an authorized recipient, please
notify the sender immediately and permanently destroy all copies of this
message and attachments.
Please consider the environment before printing this e-mail
--
Open BlueDragon Public Mailing List
http://www.openbluedragon.org/ http://twitter.com/OpenBlueDragon
mailing list - http://groups.google.com/group/openbd?hl=en
!! save a network - please trim replies before posting !!