In: Computer Science
In C Programming, Thanks
Many user-created passwords are simple and easy to guess. Write a program that takes a simple password and makes it stronger by replacing characters using the key below, and by appending "q*s" to the end of the input string. You may assume that the string does not contain spaces and will always contain less than 50 characters.
Ex: If the input is:
mypassword
the output is:
Myp@ssw.rdq*s
CODE:
#include <stdio.h>
#include <string.h>
int main()
{
char password[50]; //character array to store password
printf("Enter your password: ");
scanf("%s",password); //reading password from user
char strongerPassword[52]; //array to store updated password
int i=0;
for(i=0;i<strlen(password);i++) //looping through the password
{
if(password[i]=='i') //if current character is i
{
strongerPassword[i]='!'; //storing replacement of that character
}
else if(password[i]=='a') //if current character is a
{
strongerPassword[i]='@';
}
else if(password[i]=='m') //if current character is m
{
strongerPassword[i]='M';
}
else if(password[i]=='B') //if current character is B
{
strongerPassword[i]='8';
}
else if(password[i]=='o') //if current character is o
{
strongerPassword[i]='.';
}
else //other than any above character
{
strongerPassword[i]=password[i]; //storing same character in new password array
}
}
//appending q*s at the end
strongerPassword[i++]='q';
strongerPassword[i++]='*';
strongerPassword[i++]='s';
printf("%s",strongerPassword); //printing new password
return 0;
}
OUTPUT:
Please rate my answer if you liked it.