Question

In: Computer Science

A simple c program is needed to create encrypt and decode social security numbers. Then a...

A simple c program is needed to create encrypt and decode social security numbers. Then a validation must be used to make sure there are no invalid numbers.

**********************************************C PROGRAMMING*********************************************************************************

char social[][12] = {"164-55-0726","948-44-1038","193-74-0274","458-57-2867","093-00-1093","159-56-9731","695-21-2340","753-66-
6482","852-73-4196","648-81-1456","879-61-1829","123-87-0000","000-65-3197","741-85-9632","963-25-7418"};

Create a function that will accept as input a properly formatted social security number.
Then increment each digit by one. If the digit is "9" then make it a "0". Return a properly formatted
social security number.
Then create a function that will do the opposite. This function will take an encoded social security
number and convert it back into an unencrypted social security number. The de-encoded number is
what this function will return.

Create a function to scan all of the patient's social security numbers and detect if any of them are
invalid.
A Social Security Number (SSN) consists of nine digits, commonly written as three fields separated by
hyphens: AAA-GG-SSSS. The first three-digit field is called the "area number". The central, two-digit field
is called the "group number". The final, four-digit field is called the "serial number". Any SSN conforming
to one of the following criteria is an invalid number:

Any field all zeroes (no field of zeroes is ever assigned).
First three digits above 740
If you detect an invalid social security number, print the patient's name, their social security number,
and then either "area number", "group number", or "serial number" to indicate where the problem with
the social security number was detected.

Solutions

Expert Solution

C code

#include<string.h>
#include<stdio.h>
//encode
char *encrypt(char *ch)
{
  
for(int i=0;i<11;i++)
{
if(ch[i]=='9')
ch[i]='0';
else if(ch[i]=='-')
{
}
else
ch[i]=(char)((int)(ch[i])+1);
//printf("%s\n",ch);
}
  
return ch;
}

//en-decode
char *decrypt(char *ch)
{
  
for(int i=0;i<11;i++)
{
if(ch[i]=='0')
ch[i]='9';
else if(ch[i]=='-')
{
}
else
ch[i]=(char)((int)(ch[i])-1);
//printf("%s\n",ch);
}
  
return ch;
}
//check is valid or not
void *check(char *str , int pat)
{
char *ptr = strtok(str, "-");
   int i = atoi(ptr);
   printf( "%s \n" , str);

   if(i<=740)
   {
   printf( "Invalid Patient %d : %s area number \n" , pat , str);
   return ;
   }
   int j=1;
   while(ptr != NULL)
   {
   int k = atoi(ptr);
   if(k==0)
   {
   if(j==1)
   {
   printf( "Invalid Patient %d : %s area number \n" , pat , str);
   }
   if(j==2)
   {
   printf( "Invalid Patient %d : %s group number \n" , pat ,str );
   }
   if(j==3)
   {
   printf( "Invalid Patient %d : %s serial number \n" , pat , str );
   }
   return j;
   }
       ptr = strtok(NULL, "-");
       j++;
   }
   printf( "Valid \n" );
}
int main()
{
char social[][12] = {"164-55-0726","948-44-1038","193-74-0274","458-57-2867","093-00-1093","159-56-9731","695-21-2340","753-66-6482","852-73-4196","648-81-1456","879-61-1829","123-87-0000","000-65-3197","741-85-9632","963-25-7418"};
  
int size = sizeof(social)/sizeof(social[0]);
for(int i=0 ; i<size ; i++)
{
char *enc = encrypt(social[i]);
printf("Encrypted %s\n" ,enc) ;
char *dec = decrypt(enc);
printf("Decrypted %s\n" ,dec) ;
check(dec, i+1);
   printf( "\n" );
  
}
return 0;
}


Related Solutions

create a program that does a similar thing, but checks for authentic Social Security numbers. Here...
create a program that does a similar thing, but checks for authentic Social Security numbers. Here are two links that can help with the details. Social Security website and Social Security History website. I have to create The String with Java
the Social Security System or a perceived needed change in some aspect of the Social Security...
the Social Security System or a perceived needed change in some aspect of the Social Security System. an arguement and real life problems
C# Write a program in C# that prompts the user for a name, Social Security number,...
C# Write a program in C# that prompts the user for a name, Social Security number, hourly pay rate, and number of hours worked. In an attractive format, dis- play all the input data as well as the following: » Gross pay, defined as hourly pay rate times hours worked » Federal withholding tax, defined as 15% of the gross pay » State withholding tax, defined as 5% of the gross pay » Net pay, defined as gross pay minus...
In C++ create a simple larger3( ) function that takes 3 positive numbers as parameters and...
In C++ create a simple larger3( ) function that takes 3 positive numbers as parameters and returns the largest value of the three numbers.
Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that...
Maze in C++ Simple Maze Program – Project Specifications: 1. Create a simple maze game that a player must traverse to win. 3. The maze must be text-based and adjustable from 5x5 to 20x20. • Player gets to choose size either as: 1) any size in the range from 5-20 by 5-20. 2) selects from 4 set size options [5x5,10x10,15x15, and 20x20] • the player can choose among different mazes. • You will need to figure out how to denote...
In c++ create a program that asks for tire shop sales numbers made by 0 to...
In c++ create a program that asks for tire shop sales numbers made by 0 to 20 employees Premium tires sell for $300 and standard tires sell for $250 The wholesale cost of premium tires is $120 and the standard is $100 The program must ask for each employee's name and then the amount of premium and standard tires sold. Output the name and the total profit each employee made for the shop Output the total profits earned between all...
IN PSEUDOCODE AND C++!! Program 1: Social Security Payout. If you’re taking this course, chances are...
IN PSEUDOCODE AND C++!! Program 1: Social Security Payout. If you’re taking this course, chances are that you’re going to make a pretty good salary – especially 3 to 5 years after you graduate. When you look at your paycheck, one of the taxes you pay is called Social Security. In simplest terms, it’s a way to pay into a system and receive money back when you retire (and the longer you work and the higher your salary, the higher...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte...
C/ C++ Preferably 1. Write a simple program where you create an array of single byte characters. Make the array 100 bytes long. In C this would be an array of char. Use pointers and casting to put INTEGER (4 byte) and CHARACTER (1 byte) data into the array and pull it out. YES, an integer can be put into and retrieved from a character array. It's all binary under the hood. In some languages this is very easy (C/C++)...
I have to create a program in C++ where a user can enter as many numbers...
I have to create a program in C++ where a user can enter as many numbers as they want (they predetermine the number of values to be inputted) and then the program can echo that input back to the user and then determine if the numbers were even, odd, or a zero and it outputs how many of each were found. This is to be down with four void functions and no arrays. The program initializes the variables zero, odds,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT