is there a function (except base64) for this?I meant the string has to be encrypt then decrypt.
thanks in advanced
is there a function (except base64) for this?I meant the string has to be encrypt then decrypt.
thanks in advanced
Last edited by |HBO|; 08-31-2007 at 02:06 PM.
Encrypting/decrypting for what purpose. Base64 not really encryption, it is basicly a way to encode non-printable characters as printable ones, by encoding 6 bits at a time into one printable character.
Encryption in my vocabulary means changing something from clear-text to "unreadable" by preforming some sort of translation of the characters. These range from a simple "shuffle the alphabet" (e.g. A => B, B => C, C => D, and so on, to Z => A). So "HELLO" becomes "IFMMP". This is relatively easy to implement in a computer, but also very easy to decrypt without actually knowing the key.
There are encryption algorithms that are MUCH more complex and "intrusion proof".
--
Mats
Well, there isn't, as far as I know, any standard function that does this. There are plenty of algorithms about if you google for "encryption algorithm". There is also, I'm certain without looking, a collection of encryption/decryption libraries around in places like www.sourceforge.org or such. These will contain the encryption methods in a way that you can use in your application.
--
Mats
anyway..
i have a func like:
But this contains all ascii s.but i want just to use letter.s.(not others)Code:int i=0,j=0; while(i < strlen(source)) { from[i] += 1; i++; j++; if (j == strlen(destination)-1) j=0; }
How can i do it?
So you mean if you have "1234ABC12" it should be converted to "1234BCD12"?
Try using "isalpha()", it will return true for letters, nothing else.
--
Mats
Assuming above arrays:
Decode is obviously same but using decode array.Code:char encodechar(char c) { return encode[c - 'A']; }
This assumes that your incoming letter is an upper-case in the range 'A'..'Z' - anything else will have a undefined result.
--
Mats
even u could use just this way as well
ssharish2005Code:if(str[i] == 'z' || str[i] == 'Z') str[i] -= 25; else str[i] += 1;
Or, you could do something like (assuming strings always end with a '\0'):
Code://Buffer size incudes '\0' #define BUFFER_SIZE 255 int encrypt(char *source, char *encrypted){ int i; for (i=0; source[i]!='\0' && i <BUFFER_SIZE -1 ; i++){ encrypted[i]= source[i]+ (long long int) ( i+ tan(i) + exp(i) + pow(i+2,8)) ; }; encrypted[i]='\0'; return 0; } int decrypt(char *encrypted, char *decrypted){ int i; for (i=0; encrypted[i]!='\0' && i < BUFFER_SIZE - 1; i++){ decrypted[i]= encrypted[i] - (long long int) ( i+ tan(i) + exp(i) + pow(i+2,8)); }; decrypted[i]='\0'; return 0; }
Last edited by saman007uk; 09-02-2007 at 08:23 AM.
Try this:
Note that I had to chage the functions a bit (as tan(i) tending to -/+infinity can cause problems).Code:#include <stdio.h> #include <math.h> #define BUFFER_SIZE 256 //Buffer size incudes '\0' int encrypt(char *source, char *encrypted){ int i; for (i=0; source[i]!='\0' && i <BUFFER_SIZE -1 ; i++){ encrypted[i]= source[i]+ (long long int) ( i*8 -i+ 100*cos(i) + exp(i) + pow(i+2,8)) ; }; encrypted[i]='\0'; return 0; } int decrypt(char *encrypted, char *decrypted){ int i; for (i=0; encrypted[i]!='\0' && i <BUFFER_SIZE -1 ; i++){ decrypted[i]= encrypted[i]- (long long int) ( i*8 -i+ 100*cos(i) + exp(i) + pow(i+2,8)) ; }; decrypted[i]='\0'; return 0; } int main(void){ char source[BUFFER_SIZE]={"TestingTesting ..."}; char encrypted[BUFFER_SIZE]={0}, decrypted[BUFFER_SIZE]={0}; encrypt(source, encrypted); printf("Encrypted String\n"); printf("################\n"); printf("%s\n", encrypted); fflush(stdout); printf("################\n\n"); printf("Decrypted String\n"); printf("################\n"); decrypt(encrypted, decrypted); printf("%s\n", decrypted);fflush(stdout); printf("################\n\n"); return 0; }
Output:Note that blank spaces and new lines can also be part of the encrypted string!Code:Encrypted String ################ U�}}�;;��ׄp55� ################ Decrypted String ################ TestingTesting ... ################
Last edited by saman007uk; 09-02-2007 at 12:43 PM.
Thank you very much.
But this is the thing i am dealing with.I don't wanna it contains punctuation mark.(i meant the output must be isalnum char.)Encrypted String
################
U�}}�;;��ׄp55�
################
Regards.