Encrypting Passwords in C++


/ Published in: C++
Save to your folder(s)

A C++ algorithm which encrypts an alphanumeric password, asking the user to choose the encryption level.


Copy this code and paste it in your HTML
  1. #include <iostream>
  2. #include <string.h>
  3.  
  4. using namespace std;
  5.  
  6. void main(){
  7. char password[50]={0};
  8. int aux_password[50]={0};
  9. int encrypted_password[50]={0};
  10. char encrypted_password2[100]={0};
  11. char final_encryption[100]={0};
  12. int option;
  13. cout<<"Type a password to encrypt (0-9,A-Z,a-z): ";
  14. gets_s(password);
  15. cout<<"Select encryption level:"<<endl;
  16. cout<<"\t1.Simple mode."<<endl;
  17. cout<<"\t2.Advanced mode."<<endl;
  18. cin>>option;
  19. switch (option){
  20. case 1:
  21. cout<<">>Typed password: '";
  22. for (int i=0;i<strlen(password);i++){
  23. cout<<password[i];
  24. }cout<<"' "<<endl;
  25. cout<<">>Encrypted password: ";
  26. for(int i=0;i<strlen(password);i++){
  27. encrypted_password[i]=password[i]+12;
  28. cout<<encrypted_password[i];
  29. }cout<<endl; break;
  30. case 2: cout<<">>Typed password: '";
  31. for (int i=0;i<strlen(password);i++){
  32. cout<<password[i];
  33. }cout<<"' "<<endl;
  34. cout<<">>Encrypted password: ";
  35. for(int i=0;i<(strlen(password)*2);i++){
  36. aux_password[i]=password[i]+7;
  37. encrypted_password2[2*i+1]=aux_password[i];
  38. encrypted_password2[2*i]=i+189;
  39. final_encryption[i]=encrypted_password2[i];
  40. cout<<final_encryption[i];
  41. }cout<<endl;
  42. break;
  43. }
  44. cout<<"Developed by Santi Pagola."<<endl;
  45. system("pause");
  46. }

URL: http://`programmingeiger824.blogspot.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.