Add key input

This commit is contained in:
Stefan `Sec` Zehl 2011-06-26 14:09:32 +02:00
parent 6341b7a33b
commit 9a7c622240
1 changed files with 39 additions and 1 deletions

View File

@ -19,6 +19,7 @@
// default block size // default block size
void btea(uint32_t *v, int n, uint32_t const k[4]); void btea(uint32_t *v, int n, uint32_t const k[4]);
void hexkey(char *string, uint32_t k[4]);
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
FILE *fp; FILE *fp;
@ -51,7 +52,7 @@ int main(int argc, char *argv[]) {
break; break;
case 'k': case 'k':
// XXX: get key hexkey(optarg, k);
break; break;
case 'b': case 'b':
@ -112,6 +113,9 @@ int main(int argc, char *argv[]) {
fprintf(stderr,"Error: malloc() failed.\n"); fprintf(stderr,"Error: malloc() failed.\n");
}; };
if (verbose)
fprintf(stderr,"Key: %08x %08x %08x %08x\n",k[0],k[1],k[2],k[3]);
int cnt; int cnt;
if (verbose) if (verbose)
fprintf(stderr,"Encrypting: "); fprintf(stderr,"Encrypting: ");
@ -192,3 +196,37 @@ void btea(uint32_t *v, int n, uint32_t const k[4]) {
} while ((sum -= DELTA) != 0); } while ((sum -= DELTA) != 0);
} }
} }
void hexkey(char *string, uint32_t k[4]){
int idx=0;
int kidx=0;
int kctr=0;
int value;
char ch;
while ((ch=string[idx++])!=0){
if(ch == ' ')
continue;
if(ch == '\t')
continue;
if (ch >= '0' && ch <= '9')
value = (ch - '0');
else if (ch >= 'A' && ch <= 'F')
value = (ch - 'A' + 10);
else if (ch >= 'a' && ch <= 'f')
value = (ch - 'a' + 10);
else
continue;
k[kidx]=(k[kidx]<<4)+value;
kctr++;
if(kctr>=8){
kctr=0;
kidx++;
if(kidx>4)
return;
};
};
}