change to VodafoneUSB Modem interface
Fork of MySQLClient by
Embed:
(wiki syntax)
Show/hide line numbers
encrypt.c
00001 #include <stdio.h> 00002 #include <string.h> 00003 #include <math.h> 00004 #include "mycrypt.h" 00005 #define SCRAMBLE_LENGTH_323 8 00006 00007 typedef unsigned long ulong; 00008 typedef unsigned int uint; 00009 typedef unsigned char uchar; 00010 00011 struct rand_struct { 00012 unsigned long seed1,seed2,max_value; 00013 double max_value_dbl; 00014 }; 00015 00016 void hash_password(ulong *result, const char *password, uint password_len) 00017 { 00018 register ulong nr=1345345333L, add=7, nr2=0x12345671L; 00019 ulong tmp; 00020 const char *password_end= password + password_len; 00021 for (; password < password_end; password++) 00022 { 00023 if (*password == ' ' || *password == '\t') 00024 continue; /* skip space in password */ 00025 tmp= (ulong) (uchar) *password; 00026 nr^= (((nr & 63)+add)*tmp)+ (nr << 8); 00027 nr2+=(nr2 << 8) ^ nr; 00028 add+=tmp; 00029 } 00030 result[0]=nr & (((ulong) 1L << 31) -1L); /* Don't use sign bit (str2int) */; 00031 result[1]=nr2 & (((ulong) 1L << 31) -1L); 00032 } 00033 00034 void randominit(struct rand_struct *rand_st, ulong seed1, ulong seed2) 00035 { /* For mysql 3.21.# */ 00036 #ifdef HAVE_purify 00037 bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */ 00038 #endif 00039 rand_st->max_value= 0x3FFFFFFFL; 00040 rand_st->max_value_dbl=(double) rand_st->max_value; 00041 rand_st->seed1=seed1%rand_st->max_value ; 00042 rand_st->seed2=seed2%rand_st->max_value; 00043 } 00044 00045 double my_rnd(struct rand_struct *rand_st) 00046 { 00047 rand_st->seed1=(rand_st->seed1*3+rand_st->seed2) % rand_st->max_value; 00048 rand_st->seed2=(rand_st->seed1+rand_st->seed2+33) % rand_st->max_value; 00049 return (((double) rand_st->seed1)/rand_st->max_value_dbl); 00050 } 00051 00052 void scramble_323(char *to, const char *message, const char *password) 00053 { 00054 struct rand_struct rand_st; 00055 ulong hash_pass[2], hash_message[2]; 00056 00057 if (password && password[0]) 00058 { 00059 char extra, *to_start=to; 00060 const char *message_end= message + SCRAMBLE_LENGTH_323; 00061 hash_password(hash_pass,password, (uint) strlen(password)); 00062 hash_password(hash_message, message, SCRAMBLE_LENGTH_323); 00063 randominit(&rand_st,hash_pass[0] ^ hash_message[0], 00064 hash_pass[1] ^ hash_message[1]); 00065 for (; message < message_end; message++) 00066 *to++= (char) (floor(my_rnd(&rand_st)*31)+64); 00067 extra=(char) (floor(my_rnd(&rand_st)*31)); 00068 while (to_start != to) 00069 *(to_start++)^=extra; 00070 } 00071 *to= 0; 00072 }
Generated on Tue Jul 12 2022 20:05:45 by 1.7.2