Code.GeekInterview.com
 
Code Samples C
 

Modified String Encryption


Code ResourceAuthor: reliable  

Difficulty Level: Intermediate

Published: 13th Mar 2009   Read: 3942 times  

Filed in: C
Add Comment


 

 

Sponsored Links


 

 
Program to code and decode a given string
 


Sample Code
  1. /*
  2.  *  ModStringEncrytion.c
  3.  *
  4.  *  Description: Program to code and decode a given string
  5.  *  Created on: Mar 12, 2009
  6.  *  Author: Reliable
  7.  *  Original Code: http://code.geekinterview.com/c/string-encryption.html
  8.  *  Updates: Modified to make take in effect the '' at the end
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13.  
  14. void code(char *s,char *t)
  15. {
  16.         while(*s)
  17.         {
  18.                 *t=*s+127;
  19.                 t++;
  20.                 s++;
  21.                 if(*s == '')
  22.                         *t=*s;
  23.         }
  24. }
  25.  
  26. void decode(char *s,char *t)
  27. {
  28.         while(*s)
  29.         {
  30.                 *t=*s-127;
  31.                 t++;
  32.                 s++;
  33.                 if(*s == '')
  34.                         *t=*s;
  35.         }
  36. }
  37.  
  38. void main()
  39. {
  40.         char s1[]="I love India";
  41.         char s2[30],s3[30];
  42.  
  43.         printf("Original string is:n");
  44.         printf("%s",s1);
  45.         code(s1,s2);
  46.         printf("ncoded string is:");
  47.         printf("n%s",s2);
  48.  
  49.         decode(s2,s3);
  50.         printf("ndecoded string is:");
  51.         printf("n%s",s3);
  52.  
  53. }
Copyright GeekInterview.com


Next Article: Glittering Circle


 

Latest Code Samples

 

Popular Code Samples

 

Related Code Samples

 

Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    



Popular Coders

# Coder NameHits
1. kaivalya198933895
2. mano.mithun21571
3. deepu0817849
4. meefriend4ever8112
5. chandrikakr8081
6. sadasivathavamani7318
7. shashivaishnav7139
8. venkatakrishnansvpr7043
9. Jimmy Zorald6685
10. sripri5701

Active Coders

Refined Tags