Advertisement
Guest User

Untitled

a guest
Mar 5th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include<string>
  2. #include<iostream>
  3. void encode(int a, int b);
  4. void uncode(int a, int b);
  5. int getUncode(int a);
  6.  
  7. int main()
  8. {
  9. int a, b,c,d;
  10. cout<<"WprowadŸ klucze kodowania K(A,B)"<<endl;
  11. cin>>a>>b;
  12. c = getUncode(a);
  13. d = -b;
  14. cout<<"Twój klucz to K("<<c<<","<<d<<")"<<endl;
  15. encode(a,b);
  16. uncode(c,d);
  17. return 0;
  18. }
  19.  
  20.  
  21. void encode(int a,int b)
  22. {
  23. int len=0,i=0,j=0,temp;
  24. char s[1000];
  25. char s1[1000];
  26.  
  27. cout<<"WprowadŸ tekst do zakodowania"<<endl;
  28. cout<<"(Uwaga! Wymagane ma³e litery i maksymalnie 1000 znaków.)"<<endl;
  29. cin>>s;
  30. len = strlen(s);
  31. for(i = 0,j = 0;i<len;i++)
  32. {
  33. temp = (a*(s[i]-97)+b)%26;
  34. if(temp<0) temp += 26;
  35. s1[i]= temp +97;
  36. }
  37. s1[i]='\0';
  38. cout<<"Zakodowany ci¹g znaków:"<<endl;
  39. cout<<s1<<endl;
  40. }
  41.  
  42. void uncode(int a,int b)
  43. {
  44. int len=0,i=0,j=0;
  45. char s[1000];
  46. char s1[1000];
  47. cout<<"WprowadŸ tekst"<<endl;
  48. cout<<"(Uwaga! Wymagane ma³e litery i maksymalnie 1000 znaków.)"<<endl;
  49. cin>>s;
  50. len = strlen(s);
  51. for(i = 0,j = 0;i<len;i++)
  52. s1[i]=(a*(s[i]-97)+b)%26+97;
  53. s1[i]='\0';
  54. cout<<"Zakodowany ci¹g znaków:"<<endl;
  55. cout<<s1<<endl;
  56. }
  57.  
  58. int getUncode(int a)
  59. {
  60. int i,b;
  61. for(i = 1; i<a;i++)
  62. {
  63. b = ( 26*i + 1 )/a;
  64. if(( 26*i + 1 )%a==0)
  65. return b;
  66. SYSTEM("PAUSE");
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement