Submit a C file with the following two functions defined. unsigned char permutat
ID: 3884612 • Letter: S
Question
Submit a C file with the following two functions defined. unsigned char permutation (unsigned char x) unsigned char inverse(unsigned char y) The first C function should implement any non-trivial permutation function (ie, a one-to-one and onto function from byte to byte) of your choosing using at least three C operations. For the function to be invertible, each individual operation you choose has to be invertible too, so think about what combination of C operations are invertible and string three or more of them together. The second C function should be the inverse of the first C function. If you're successful, x == inverse (permutation(x)) should be true for every x. The file you submit should be named exactly hw1_permutation.c.Explanation / Answer
#include<stdio.h>
unsigned char permutation(unsigned char);
unsigned char Inverse(unsigned char);
int main()
{
unsigned char c,d,x,y;
printf("Enter any character: ");
scanf("%c",&x);
y=permutation(x);
d=Inverse(y);
if(x==d)
{
printf("True");
}
return 0;
}
unsigned char Inverse(unsigned char y)
{
int il,ir,f;
il=invrightshift2(y);
ir=invleftshift4(il);
f=invrightshift2(ir);
printf(" Inverse Value is %c ",f);
return f;
}
unsigned char permutation(unsigned char X)
{
unsigned char b=X;
printf("ASCII %d",sizeof(X));
int d,p,r,l,sum,f;
d=(int)X;
//printf(" %d",convert(d));
r=rightshift2(d);
l=leftshift4(r);
f=rightshift2(l);
//printf(" Permuted value is %c",f);
//printf(" Right Shift %d",p);
//printf(" %d Left",leftshift4(p));
//Inverse((char)f);
return f;
}
int rightshift2(int v)
{
//printf(" %d",v>>2);
return v>>2;
}
int leftshift4(int v)
{
return v<<4;
}
int invrightshift2(int v)
{
//printf(" %d",v>>2);
return v<<2;
}
int invleftshift4(int v)
{
return v>>4;
}