Advertisement
Caiwan

Untitled

May 12th, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. namespace {
  2.     char result[10];
  3. }
  4.  
  5. char* getNextStep(char *key){
  6.     int range1 = 30;
  7.     int range2 = 29;
  8.     char* charTable = "0123456789ABCDEFGHIJKLMNZPQRSTU";
  9.     int inputConverted = 0;
  10.     int keyLength = strlen(key);
  11.     int resultCharCode = 0;
  12.     int charIndex = 0;
  13.     int i;
  14.  
  15.     memset(result, 0, 10);
  16.  
  17.     for(i=0;key[i];i++){
  18.         charIndex = strchr(charTable,key[i])-charTable;
  19.         inputConverted += charIndex*((int)pow((float)range1,(float)(keyLength-i-1)));
  20.     }
  21.  
  22.     if (inputConverted <= 0) {strcpy(result, "INVALID KEY"); return result;}
  23.  
  24.     i = 0;
  25.  
  26.     while (inputConverted >= range2){
  27.       resultCharCode = inputConverted % range2;
  28.       result[i] = charTable[resultCharCode];
  29.       inputConverted /= range2;
  30.       i++;
  31.     }
  32.     result[i] = charTable[inputConverted];
  33.  
  34.     char *buf = new char[strlen(result)+1];
  35.  
  36.     int l = strlen(result);
  37.     strcpy(buf, result); memset(result, 0, 10);
  38.     for (i=0; buf[i]; i++) result[i] = buf[l-1-i];
  39.    
  40.     delete buf;
  41.  
  42.     return result;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement