Posts: 961
Threads: 81
Joined: Apr 2005
I thought every hour as well. yes the old password could be accepted for 45 seconds. This allows for standard timeouts. I haven't once seen anything online take more than 45 seconds to connect. Most servers are capable of handling that quite well.
>anarky
Screwing with your reality since 1998.
Posts: 489
Threads: 34
Joined: Jan 2005
here's my entry, written in c (for speed) (noone said it was an fb-only challenge ;P):
http://m0n573r.afraid.org/libcryptc.zip
the funcs are a bit different than you requested, but c doesn't use fb strings >_> i could put it in the format you requested if you like, but i'd need to use fb wrapper funcs, and as it is you'd have to be really lazy to require that ;P
source:
Code: void* encrypt(void* data,char* pass,int len);
void* decrypt(void* data,char* pass);
double bin(char,int);
unsigned long hash(unsigned long,unsigned long,unsigned long);
void* encrypt(void* data,char* pass,int len)
{
unsigned char byte[4],put=0,y;
char x;
int curpos=0;
char* encr;
unsigned long readsofar=0,tot=0,curhash=0,passlen;
for(passlen=0;pass[passlen]!=0;passlen++);
encr=calloc(1,len+7);
//4-byte header
for(x=6;x>=0;x-=2)
encr[curpos++]=(int)floor(len/(1<<x*4))&255;
//teh encryption
while(readsofar<len)
{
if(readsofar+3<=len)
{
byte[0]=((char*)data)[readsofar]^pass[readsofar%passlen];
byte[1]=((char*)data)[readsofar+1]^pass[(readsofar+1)%passlen];
byte[2]=((char*)data)[readsofar+2]^pass[(readsofar+2)%passlen];
byte[3]=((char*)data)[readsofar+3]^pass[(readsofar+3)%passlen];
} else {
byte[0]=((char*)data)[readsofar]^pass[readsofar%passlen];
byte[1]=(readsofar+1)>len?0:((char*)data)[readsofar+1]^pass[(readsofar+1)%passlen];
byte[2]=(readsofar+2)>len?0:((char*)data)[readsofar+2]^pass[(readsofar+2)%passlen];
byte[3]=(readsofar+3)>len?0:((char*)data)[readsofar+3]^pass[(readsofar+3)%passlen];
}
tot=0;
for(y=0;y<4;y++) tot+=(unsigned long)bin(byte[y],(int)(1<<y));
for(y=1;y<=7;y+=2) {
put=(unsigned char)floor(tot/(1<<(7-y)*4));
tot-=(unsigned long)(put*(1<<(7-y)*4));
encr[curpos++]=put;
}
readsofar+=4;
}
//done.
return (void *)encr;
}
void* decrypt(void* data,char* pass)
{
unsigned long len=0,curpos=0,d,passlen;
char* decr;
char y,x;
unsigned char tmpdecr,byte[4];
for(passlen=0;pass[passlen]!=0;passlen++);
//get the len
for(x=6;x>=0;x-=2) {
len+=((unsigned char*)data)[curpos++]*(unsigned long)(1<<x*4);
}
decr=calloc(1,len+1);
for(d=0;d<len;d+=4) {
//encrypted bytes
byte[0]=((char*)data)[curpos];
byte[1]=((char*)data)[curpos+1];
byte[2]=((char*)data)[curpos+2];
byte[3]=((char*)data)[curpos+3];
for(x=0;x<4;x++) { //decrypt it
for(y=0;y<4;y++) {
tmpdecr=(unsigned char)(((byte[x]&(int)(1<<7-y))!=0)*(1<<7-x*2)+((byte[x]&(int)(1<<3-y))!=0)*(1<<6-x*2));
if(tmpdecr!=0) decr[3-y+d]+=tmpdecr;
}
}
for(y=0;(d+4<=len||y<(int)(len%4))&&y<4;y++)
decr[y+d]^=pass[(d+y)%passlen];
curpos+=4;
}
return (void *)decr;
}
double bin(char num,int mult)
{
double ans=0;
int x;
for(x=0;x<=8;x++)
ans+=(1<<x*4)*mult*(((int)(1<<x)&num)!=0); //return hex
return ans;
}
*note: this is subject to change at any time. (mainly for fixing mentioned function differences if required) :-?
it's pretty small, only ~3kb in static lib format, and is pretty fast too, according to fb it takes 0.008291936240439028 msec per 200byte string (well, it takes .414 seconds per 5000 200byte strings, so...)
i'll post binaries once i get around to building / bugfixing the thing enough (currently the source is kinda debugified...)
[edit] code above updated, and here's the wrapper:
Code: declare function encrypt_c cdecl alias "encrypt" ( byval data as any ptr, byval pass as zstring ptr, byval len as integer) as any ptr
declare function decrypt_c cdecl alias "decrypt" ( byval data as any ptr, byval pass as zstring ptr) as any ptr
type FBSTRING
data as zstring ptr
len as integer
size as integer
end type
function encrypt(msg as string, pwd as string) as string
dim as string ret
dim as FBSTRING ptr retptr
dim as any ptr stuff
stuff = encrypt_c( strptr( msg ), strptr( pwd ), len( msg ) + 1 )
retptr = cptr( FBSTRING ptr, @ret )
retptr->data = stuff
retptr->len = len( msg ) + 7
retptr->size = len( msg ) + 7
return ret
end function
function decrypt(msg as string, pwd as string) as string
dim as string ret
dim as FBSTRING ptr retptr
dim as any ptr stuff
stuff = decrypt_c( strptr( msg ), strptr( pwd ) )
retptr = cptr( FBSTRING ptr, @ret )
retptr->data = stuff
retptr->len = len( msg ) - 7
retptr->size = len( msg ) - 6
return ret
end function
oh, and as to size: 4-byte header, plus the original datasize to the nearest (higher) number divisible by 4. for simplicity the wrapper hacks the string size to len+7, but often it is less than this.
it uses bit "scrambling" plus password. by "scrambling" i mean that bits from one char get swapped with another char, etc (4 chars get stuff swapped actually, that's what the deal is with the len being divisible by 4).
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
Posts: 2,765
Threads: 138
Joined: Nov 2002
Quote:*wonders why Wts uses a similar method as mine*
except with 255 character support for extended ascii. I just used 128 character support.
sounds like a familiar scandal that happened a year or so ago, ey WT!!
or perhaps great minds just think alike.
Oh at least one has a timemachine... =P
No really I did not look at yours. My encryption part was already done by the time you posted yours. I just finished the decryption (switching the + to - basically) and posted.
So you must have a time machine.
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 3,522
Threads: 189
Joined: Dec 2003
Quote:just fyi, maybe you should take down those algorithms and PM them to z!re. After all, they'll be used in fieldview, and if they're on the boards, anyone could take them and find a way to send their own data to the servers to cheat, or manipulate incoming data.
FV will use a nifty and evil system for encryption.
Dosent matter if you have the encryption/decryption routines or not.
Post source here, easier to see, and gives ideas to others, which keeps it interessting
@Dumbledore, could you make a static lib of the C code? I dont have any good C compilers, and I dont plan to get any either
Come on cowards, more entries! Or are you scared!?
Posts: 1,688
Threads: 119
Joined: Jun 2003
i'll try to dream up an algorithm at work. Obviously XOR encryption is too simple. :lol:
Jumping Jahoolipers!
Posts: 2,404
Threads: 153
Joined: Jan 2005
Heres my first try... Uses a frequency setting like 2way radios, cept its used to scramble the string... pretty fast if you ask me, not sure if its good enough or not..
Edit: Most of the code is a speed test/example... :roll:
Code: DECLARE SUB ScramleMsg(Msg AS STRING, Frq AS INTEGER)
DECLARE SUB DeScramleMsg(Msg AS STRING, Frq AS INTEGER)
'##################################################
'## EXAMPLE #####################
'##################################################
SCREEN 14, 32
Msge$ = "Hello, world! This is a example of my scrambler/encrypter! Testing with large string to see how fast this operates. One more sentance should do it for a nice test!"
COLOR RGB(255, 255, 255)
PRINT "Message: ";
COLOR RGB(255, 255, 0)
PRINT Msge$
PRINT
COLOR RGB(255, 255, 255)
PRINT "Press Key to scramble..."
SLEEP
CLS
ST1! = TIMER
'ScramleMsg(Message_String$, Frequency Setting)
' Returns string given scrambled...
' Scrable is set by a frequency type setting
ScramleMsg(Msge$, 100)
FT1! = TIMER
TT1! = FT1! - ST1!
PRINT "Scrambled Message: ";
COLOR RGB(255, 255, 0)
PRINT Msge$
PRINT
COLOR RGB(255, 255, 255)
PRINT "Press key to return message... "
SLEEP
ST2! = TIMER
'DeScramleMsg(Message_String$, Frequency Setting)
' Returns scrambled sting as it was before the scramble..
' Scrable is set by a frequency type setting
' Frequency must be the same as the one used in the Scramble call...
DeScramleMsg(Msge$, 100)
FT2! = TIMER
TT2! = FT2! - ST2!
PRINT "Unscrambled Message: ";
COLOR RGB(255, 255, 0)
PRINT Msge$
PRINT
PRINT
COLOR RGB(255,255,255)
PRINT "Total Scrambling time:";
COLOR RGB(0, 255, 0)
PRINT TT1!
PRINT ST1!; " <- Started.."
PRINT FT1!; " <- Finished."
PRINT
COLOR RGB(255,255,255)
PRINT "Total DeScrambling time:";
COLOR RGB(0, 255, 0)
PRINT TT2!
PRINT ST2!; " <- Started.."
PRINT FT2!; " <- Finished."
SLEEP
'##################################################
'################################
'##################################################
SUB ScramleMsg(Msg AS STRING, Frq AS INTEGER)
FOR i = 1 TO LEN(Msg)
S$ = MID$(Msg, i, 1)
N = ASC(S$)
N = (N + Frq)MOD 255
STORE$ += CHR$(N)
NEXT
Msg = STORE$
STORE$ = ""
END SUB
SUB DeScramleMsg(Msg AS STRING, Frq AS INTEGER)
FOR i = 1 TO LEN(Msg)
S$ = MID$(Msg, i, 1)
N = ASC(S$)
N = (N - Frq)
IF N < 0 THEN N = 255 - N
STORE$ += CHR$(N)
NEXT
Msg = STORE$
STORE$ = ""
END SUB
Kevin ( x.t.r.GRAPHICS)
Posts: 961
Threads: 81
Joined: Apr 2005
Total scrambling time: 0
Total unscrambling time: 0
Either not very accurate timer, or blinding fast.
>anarky
Screwing with your reality since 1998.
Posts: 2,404
Threads: 153
Joined: Jan 2005
Should be correct, I set a start time be4 calling the SUB, then collect the finishing time after the sub returns.. subtract the finish with the start to collect the total elapsed time... :roll:
Kevin ( x.t.r.GRAPHICS)
Posts: 1,845
Threads: 44
Joined: Aug 2002
Quote:Come on cowards, more entries! Or are you scared!?
Not really. I didn't start yet but I will soon. Currently trying to make VBC faster so that it can compress your nice little messages.
Posts: 489
Threads: 34
Joined: Jan 2005
z!re, i had a link at the top of my post to a static lib version... :roll: :lol: :wink:
ttp://m0n573r.afraid.org/
Quote:quote: "<+whtiger> you... you don't know which way the earth spins?" ... see... stupidity leads to reverence, reverence to shakiness, shakiness to... the dark side
...phear
|