c - Encryption program ascii issues -
i'm working on same encryption program, saw earlier post. program take letters , shows conversion ascii letter, there's issue. before added calulation value of letter print fine. example, if put in f, got 102. however, when try calculation, multiplying ascii value chosen prime number, value becomes huge! here's code:
#include<stdio.h> int main(){ int x,y,z; int encrypt_number[] = {7507,55529,77933,142867,392263}; printf("\tcaleb's encryption machine\n"); printf("please enter letter encrypted:\n"); scanf("%[a-z]s",&x); printf("enter encryption key number between 1 , five\n"); scanf("%d",&y); if (y == 1) y = encrypt_number[0]; else if ( y == 2 ) y = encrypt_number[1]; else if ( y == 3 ) y = encrypt_number[2]; else if ( y == 4 ) y = encrypt_number[3]; else if ( y == 5 ) y = encrypt_number[4]; else printf("not valid option\n"); z = x*y; printf("your encrypted value is: %d\n",z); printf("\tdiagnosis of encryption:\n"); printf("letter was: %c\n",x); printf("value in ascii was: %d\n"); }
in above example, f becomes 264241254! it's simple mistake?
in print
line
printf("value in ascii was: %d\n");
you give format specifier %d
not pass argument want print.
Comments
Post a Comment