November 3, 2004 at 12:20 pm
Hello to all. I wonder if someone had or has worked with BBX, if so I need your help!!!!!!!!!!!!!!!!!!
This the case, one of the developers in my company created back when... a short script in BBX which helped then to encrypt some data within their system.
The script reads as follows:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
BEGIN
INPUT A$
FOR X = 1 TO LEN (A$)
IF FPT (X/4) <> 0 THEN LET B$=B$+CHR(ASC(AS(X,3)+3*X) ELSE B$=B$+CHR(AS C(A$(X,1)) -6*X)
NEXT X
PRINT B$
END
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
I think the script in plain english is simple, go to the field, count the numbers of characters in the filed, set the ecryption to change characters and return the new numbers as it was modified by the script.
OK, here is the thing, I have no idea how to change tis script to T-SQL. Any ideas???? As always I am desperate to get an answer as soon as possible and any help will be very much appreciated!! HELP!!!!
almost to the border between panic and terror!! Thank you for all your assistance!!
November 3, 2004 at 10:07 pm
I've not heard of BBX, but this looks like straight BASIC to me. Having said that, I have no idea what the FPT function does, please elaborate.
It should then be possible to write a UDF that will take a string as input and return the 'encrypted' string as above.
As an aside, are you sure that you want to continue with this method of 'encryption' - hardly the most sophisticated algorithm I've seen - and now everyone who logs in to this site has effectively been given the decryption key - I hope it's not storing credit card details!
Cheers
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 3, 2004 at 10:52 pm
Thanks Phil, I modified the script before I post it, but the basic lines are there and not it is not that sensitive. Is just some data we want to encrypt but it is not as sensitive as anyone can think. We are playing with different methods of encrypting and so far I have been able to do tha translation to T-SQL. This is the only one that I have no clue how to transform to t-sql (I do not know the FPT function does either!)
November 3, 2004 at 11:10 pm
No problem. I did a search on the web and found the following link about the FPT function ... do you think that is it?
http://www.basis.com/docsonline/commands/fpt_function.htm
If I create a user defined function that accepts a string as a parameter and returns the string encrypted as per the algorithm you described, is that going to be sufficient for what you need?
Regards
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 4, 2004 at 8:04 am
What does AS do?
November 4, 2004 at 4:41 pm
Missed that. I have no idea what the as() function does. Any ideas, anyone?
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 4, 2004 at 8:30 pm
Sorry guys, I meant asc for ascii, not "as c" as I typed. my mind sometimes works faster than my fingers!!!! Thank you very much for your input.
November 4, 2004 at 10:01 pm
I think we were both referring to the ASC(AS(X,3) bit, which does not contain a trailing 'C'. I actually think you might have meant A$, rather than AS. I think it may also be missing a closing ')'?
Now that I might have decrypted your typing , I am wondering what A$(X,3) is going to return, for a given value of X.
Eg if the word is 'Chicken' and X = 5, then we are looking for the value of
chicken(5,3)
which I am struggling to guess at. Chicken(5,1) could mean 'k' - is this another mistype???
Also, what is the initial value of B$? Empty string?
We'll get there in the end!
Cheers
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 5, 2004 at 6:03 am
BBx is an implementation of Business Basic. Note that there isn't a Mid() function. Substrings are obtained using an array-like notation. First number is the starting position, second (optional) number is the length of the substring. If the second number is left out, the the remainder of the string is returned.
LET A$ = "Hello, World"
A$(1,5) returns "Hello"
A$(3) returns "llo, World"
A$(8,1) returns "H"
You can check out this link for more information:
ftp://ftp.basis.com/pub/documentation/pdf/P5_vp5.pdf
November 10, 2004 at 11:46 pm
Check this out:
declare @STR varchar(255), @enc varchar(255), @i int
set @STR = 'have a banana'
set @enc = ''
set @i = 1
while @i <= len(@str)
begin
if @i / 4.0 - @i /4 0
begin
set @enc = @enc + char(ascii(substring(@str,@i,1)) + 3 * @i)
end
else
begin
set @enc = @enc + char(ascii(substring(@str,@i,1)) - 6*@i)
end
set @i = @i + 1
end
select @STR as string, @enc as encrypted
When I was doing some testing, this seemed to work OK, except that for some strings, the argument of the char() function goes negative, which is out of range - in which case CHAR returns null and the whole return string is consequently set to NULL. Once you have decided how to handle these out-of-range arguments, slight amendments will have to be made to the routine to accommodate them.
Regards
Phil
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply