home *** CD-ROM | disk | FTP | other *** search
- /* this program convert a string containing differents token separated with *
- and return the string needed to be put in _challenge1.htm.
- for example : type "The_Seeker*Sandman" when prompted for the input string
- */
-
- #include <math.h>
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
-
- const char* al="AH2ypN(TZ>RCKi*z;U7G)?dQ<Je]0-=~M$%ahruoSnWEx4YFqmL(5`IOPB}|s6g:#&Vj+l1_[cvD,9./^f3@tXbw!k8";
-
-
- //return the first 2 char in a string as a integer (from 0 to 99)
- int stoi(char* st) {return ((st[0]&0x0F)*10+(st[1]&0x0F));}
-
- //convert int i to a 2 char string
- void itos(char* buff, int i) {sprintf(buff,"%02d",i);}
-
-
- //return the index of char c in the string al
- int GetCharIndex(char c)
-
- {
- int i;
- for (i=0; i<strlen(al); i++)
- {
- if (al[i] == c) return i;
- }
- printf("error\n");
- return 0;
- }
-
-
- //append to dest the string source crypted with the 'offset' a
- void CryptString(char* dest, char* source, int a)
-
- {
- int i;
- char buff[3];
- itos(buff, strlen(source)+89); //append string length
- strcat(dest, buff);
- for (i=0; i<strlen(source); i++)
- {
- itos(buff, GetCharIndex(source[i])+a); //append each char
- strcat(dest, buff);
- }
- }
-
-
- void main(void)
-
- {
- char buff[80];
- char inputstring[30]; //hold the input string (The_Seeker*Sandman for example)
- int a_offset; //hold the crypting offset
- char* tok; //will contain each substring to be crypted
-
- FILE *out;
-
- printf("enter string to convert : ");
- scanf("%s", inputstring);
- printf("enter 'a' offset : ");
- scanf("%d", &a_offset);
-
- out = fopen("code.txt", "at");
- fprintf(out,"'%s' crypted with offset %d -> ", inputstring, a_offset);
-
-
- itos(buff, a_offset+91); //begin to store the a_offset
-
- tok = strtok(inputstring, "*"); //get the first substring
- if (tok)
- {
- do
- {
- printf("crypting '%s' ...\n", tok);
- CryptString(buff, tok, a_offset); //store it
- tok = strtok(NULL, "*"); //get the next substring ... and loop to store it too
- }
- while(tok!=NULL);
- }
-
-
- printf("%s", buff);
- fprintf(out,"%s\n", buff);
-
- fclose(out);
- int ch = getch();
- }
-