Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace {
- char result[10];
- }
- char* getNextStep(char *key){
- int range1 = 30;
- int range2 = 29;
- char* charTable = "0123456789ABCDEFGHIJKLMNZPQRSTU";
- int inputConverted = 0;
- int keyLength = strlen(key);
- int resultCharCode = 0;
- int charIndex = 0;
- int i;
- memset(result, 0, 10);
- for(i=0;key[i];i++){
- charIndex = strchr(charTable,key[i])-charTable;
- inputConverted += charIndex*((int)pow((float)range1,(float)(keyLength-i-1)));
- }
- if (inputConverted <= 0) {strcpy(result, "INVALID KEY"); return result;}
- i = 0;
- while (inputConverted >= range2){
- resultCharCode = inputConverted % range2;
- result[i] = charTable[resultCharCode];
- inputConverted /= range2;
- i++;
- }
- result[i] = charTable[inputConverted];
- char *buf = new char[strlen(result)+1];
- int l = strlen(result);
- strcpy(buf, result); memset(result, 0, 10);
- for (i=0; buf[i]; i++) result[i] = buf[l-1-i];
- delete buf;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement