Submit a C file with the following two functions defined. unsigned char permutat
ID: 3886119 • 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");
}
reutrn 0;
}
unsigned char inverse(unsigned char y)
{
int il,ir,f;
il=invirghtsgift2(y);
ir=invleftshift4(il);
f=invrightshift2(ir);
printf("/ninverse value is %c/n/n",f);
return f;
}
unsigned char permutation(unsigned char X)
{
unsigned char b=X;
printf("ASCII%d",sizeof(X));
int d,p,r,i,sum,f;
d=(int)X;
//printf("/n/n%d",convert(d));
r=rightshift2(d);
l=leftshift4(r);
f=rightshift2(i);
//printf("/nRight shift %d",p);
//printf("/n%d Left",leftshift4(p));
//inverse((char)f);
return f;
}
int rightshift2(int v)
{
//printf("/n/n%d",v>>2);
return v>>2;
}
int leftshift4(int v)
{
return v<<4;
}
int invrightshift2(int v)
{
//printf("/n/n%d",v>>2);
return v<<2;
}
int invleftshift4(int v)
{
return v>>4;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.