/* Calculation of CRC (Cyclic Redundancy Check)*/
#include< stdlib.h>
#include< conio.h>
#include< stdio.h>
void main()
{
int i,j,n,g,a,arr[20],gen[20],b[20],q[20],s;
clrscr();
printf("Transmitter side:");
printf("\nEnter no. of data bits:");
scanf("%d",&n);
printf("Enter data:");
for(i=0;i< n;i++)
scanf("%d",&arr[i]);
printf("Enter size of generator:");
scanf("%d",&g);
do{
printf("Enter generator:");
for(j=0;j< g;j++)
scanf("%d",&gen[j]);
}
while(gen[0]!=1);
printf("\n\tThe generator matrix:");
for(j=0;j< g;j++)
printf("%d",gen[j]);
a=n+(g-1);
printf("\n\tThe appended matrix is:");
for(i=0;i< j;++i)
arr[n+i]=0;
for(i=0;i< a;++i)
printf("%d",arr[i]);
for(i=0;i< n;++i)
q[i]= arr[i];
for(i=0;i< n;++i)
{
if(arr[i]==0)
{
for(j=i;j< g+i;++j)
arr[j] = arr[j]^0;
}
else
{
arr[i] = arr[i]^gen[0];
arr[i+1]=arr[i+1]^gen[1];
arr[i+2]=arr[i+2]^gen[2];
arr[i+3]=arr[i+3]^gen[3];
}
}
printf("\n\tThe CRC is :");
for(i=n;i < a;++i)
printf("%d",arr[i]);
s=n+a;
for(i=n;i< s;i++)
q[i]=arr[i];
printf("\n");
for(i=0;i< a;i++)
printf("%d",q[i]);
getch();
}
/* Output
Transmitter side:
Enter no. of data bits:8
Enter data:1 0 1 0 0 0 0 1
Enter size of generator:4
Enter generator:1 0 0 1
The generator matrix:1001
The appended matrix is:10100001000
The CRC is :111
10100001111
*/
Thursday, October 2, 2008
Subscribe to:
Post Comments (Atom)
24 comments:
thanks for the information it was really good
thanka a lot.............
Doesnt work for all inputs dude.....
thankz for the information
hey buddy thanx a lot...
thanq
thanq
good work buddy
Thank you very much sir
good thinking
main()
{
int a[10],b[10],c[10],i,k,j,n,s=0,t=0;
printf("enter size of data\n");
scanf("%d",&n);
printf("enter data to be transfer bit by bit\n");
for (i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("enter size of polynomial\n");
scanf("%d",&k);
printf("enter generator polynomial bit by bit\n");
for (j=0;j<k;j++)
{
scanf("%d",&b[j]);
}
for (i=0;i<(k-1);i++)
{
a[n+i]=0;
}
for (i=0;i<(k+n-1);i++)
{
printf("%d",a[i]);
}
printf("\n");
//for division
for (i=0;i<k;i++)
{
c[i]=a[i];
}
for (t=0;t<(n-1);t++)
{
for (j=1;j<k;j++)
{
c[j-1]=c[j]^b[j];
c[j]=a[k+s];
}
for (i=0;i<k;i++)
printf("%d",c[i]);
printf("\n");
s++;
}
//for last loop
for(i=0;i<k;i++)
c[i]=c[i]^b[i];
//print the remainder
for (i=0;i<k;i++)
printf("%d",c[i]);
}
******************
this calculate remainder fcs ok
hey this is bit hard but it definately works use it on linux, rest any problem mail me @ arpitbhatnagarmnit@gmail.com
Hi,
Lionel please could you give me your email , i have some problem to paste your program RSA in my Xilinx SDK, it doesnt work for me , please could you help
i'm waiting for your help in deed
best regards
Lionel,
please could you just give me your email, i have some question in RSA Algorithm, it doesnt work for me when i past it in SDK Xilinx,
Please could you help
Hi. The program is really helpful. But why din you include the receiver checking part? May be this would serve the purpose.
/* Calculation of CRC of a data*/
#include
#include
#include
void main()
{
int i,j,n,g,a,arr[20],gen[20],b[20],q[20],x[20],check,s;
check=0;
clrscr();
printf("\n\n\t ****** CYCLIC REDUNDANCY CHECK ****** ");
printf("\n\t Transmitter side:");
printf("\n\t Enter no. of data bits: ");
scanf("%d",&n);
printf("\n\t Enter the data to be sent: \n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
printf("\n\t Enter no. of divisor bits: ");
scanf("%d",&g);
do
{
printf("\n\t Enter the generator data: \n");
for(j=0;j<g;j++)
scanf("%d",&gen[j]);
}while(gen[0]!=1);
printf("\n\t The divisor is:");
for(j=0;j<g;j++)
printf("%d",gen[j]);
a=n+(g-1);
printf("\n\t The transmitter side data is:");
for(i=0;i<j;++i)
arr[n+i]=0;
for(i=0;i<a;++i)
printf("%d",arr[i]);
for(i=0;i<n;++i)
q[i]= arr[i];
for(i=0;i<n;++i)
{
if(arr[i]==0)
{
for(j=i;j<g+i;++j)
arr[j] = arr[j]^0;
}
else
{
arr[i] = arr[i]^gen[0];
arr[i+1]=arr[i+1]^gen[1];
arr[i+2]=arr[i+2]^gen[2];
arr[i+3]=arr[i+3]^gen[3];
}
}
printf("\n\t The CRC is :");
for(i=n;i<a;++i)
printf("%d",arr[i]);
for(i=0;i<g-1;++i)
x[i]=arr[i];
s=n+a;
for(i=n;i<s;i++)
q[i]=arr[i];
printf("\n");
for(i=0;i<a;i++)
printf("%d",q[i]);
getch();
clrscr();
printf("\n\t Receiver side:");
printf("\n\t Enter no. of data bits received: ");
scanf("%d",&n);
printf("\n\t Enter the data received: \n");
for(i=0;i<n;i++)
scanf("%d",&arr[i]);
for(i=n,j=g-1;i<a,j<0;i++,j--)
arr[i]=q[j];
printf("\n\t The receiver side data is:");
for(i=0;i<a;++i)
printf("%d",arr[i]);
for(i=0;i<n;++i)
q[i]=arr[i];
for(i=0;i<n;++i)
{
if(arr[i]==0)
{
for(j=i;j<g+i;++j)
arr[j] = arr[j]^0;
}
else
{
arr[i] = arr[i]^gen[0];
arr[i+1]=arr[i+1]^gen[1];
arr[i+2]=arr[i+2]^gen[2];
arr[i+3]=arr[i+3]^gen[3];
}
}
printf("\n\t The CRC at the receiver is:");
for(i=n;i<a;++i)
printf("%d",arr[i]);
s=n+a;
for(i=n;i<s;i++)
q[i]=arr[i];
printf("\n");
i=0;
while(i<a)
{
if(q[i]==0)
check=0;
else
check=1;
i++;
}
printf("\n\n Result of CRC Error detection is: ");
if(check==0)
printf("\n\t Data is accepted successfully!");
else
printf("\n Resend the data again!");
getch();
}
Output:-
****** CYCLIC REDUNDANCY CHECK ******
Transmitter side:
Enter no. of data bits: 6
Enter the data to be sent:
1 0 0 1 0 0
Enter no. of divisor bits: 4
Enter the generator data:
1 1 0 1
The divisor is: 1101
The transmitter side data is:100100000
The CRC is: 001
100100001
Receiver side:
Enter no. of data bits received: 6
Enter the data received:
1 0 0 1 0 0
The receiver side data is:100100001
The CRC at the receiver is:000
100100000
Result of CRC Error detection is:
Data is accepted successfully!
nicely done...thnq :)
nicely done.. thnq :)
****rsa alg***
#include
#include
#include
#include
int prime[] = {7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
127, 131, 137, 139, 149, 151, 157, 163};
void main(){
unsigned int e, d, m, c, p, q, i;
unsigned long n, fi;
int rm1, rm2;
clrscr();
printf("\t\t************ \n");
printf("\t\t RSA algorithm \n");
printf("\t\t************* \n");
printf("------------ Sender side -----------\n");
p = prime[abs(time()) % 36];
do{
q = prime[abs(rand() + time()) % 36];
}
while(q == p);
printf("the two primes that were selected\n");
printf("p = %d, q = %d \n", p, q);
n = p * q;
fi = (p - 1) * (q - 1);
for(e = 2; e < n; e++)
if(gcd(e, fi) == 1)
break;
for(d = 2; d < n; d++)
if(d * e % fi == 1)
break;
printf("\n public key e = %d\n n = %d", e, n);
printf("\nenter a number(i.e., message to be sent): ");
scanf("%d", &m);
e = powmod(m, e, n);
printf("\n encrypted message = %d \n\n");
printf("--------- receiver side---------\n");
m = powmod(e, d, n);
printf("private key d = %d \n n = %d\n ",d, n);
printf("decrypted message = %d\n", m);
getch();
}
gcd(int m, long n)
{
int a;
a = m % n;
while( a != 0){
m = n;
n = a;
a = m % n;
}
return n;
}
powmod(int msg, int e, int n){
int powr, d;
unsigned long num, res;
if(n == 0 || e < 0)
return 0;
res = 1;
num = msg;
powr = e;
while(powr != 0){
d = powr % 2;
powr = powr / 2;
if(d == 1)
res = ((res % n) * (num % n)) % n;
num = ((num % n) * (num % n)) % n;
}
return res;
}
****rsa algorithm*****
#include
#include
#include
#include
int prime[] = {7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59,
61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127,
127, 131, 137, 139, 149, 151, 157, 163};
void main(){
unsigned int e, d, m, c, p, q, i;
unsigned long n, fi;
int rm1, rm2;
clrscr();
printf("\t\t************ \n");
printf("\t\t RSA algorithm \n");
printf("\t\t************* \n");
printf("------------ Sender side -----------\n");
p = prime[abs(time()) % 36];
do{
q = prime[abs(rand() + time()) % 36];
}
while(q == p);
printf("the two primes that were selected\n");
printf("p = %d, q = %d \n", p, q);
n = p * q;
fi = (p - 1) * (q - 1);
for(e = 2; e < n; e++)
if(gcd(e, fi) == 1)
break;
for(d = 2; d < n; d++)
if(d * e % fi == 1)
break;
printf("\n public key e = %d\n n = %d", e, n);
printf("\nenter a number(i.e., message to be sent): ");
scanf("%d", &m);
e = powmod(m, e, n);
printf("\n encrypted message = %d \n\n");
printf("--------- receiver side---------\n");
m = powmod(e, d, n);
printf("private key d = %d \n n = %d\n ",d, n);
printf("decrypted message = %d\n", m);
getch();
}
gcd(int m, long n)
{
int a;
a = m % n;
while( a != 0){
m = n;
n = a;
a = m % n;
}
return n;
}
powmod(int msg, int e, int n){
int powr, d;
unsigned long num, res;
if(n == 0 || e < 0)
return 0;
res = 1;
num = msg;
powr = e;
while(powr != 0){
d = powr % 2;
powr = powr / 2;
if(d == 1)
res = ((res % n) * (num % n)) % n;
num = ((num % n) * (num % n)) % n;
}
return res;
}
Also try this.........very compact and very simple to understand...........
To run this program just call this from your main function
like :-
main() {
crc();
}
By
Dixit Singla
void crc() {
int array[30] = {1,1,0,0,0,1,1,0,1,0,1,1,0,1,0,1};
int divi[10] = {1,0,0,1,1};
int mess[20];
int n = 16,d = 5,i;
int app = d-1;
for(i = 0 ; i < n ; i++ ) {
mess[i] = array[i];
}
for(i = 0 ; i < app ; i++) {
array[n+i] = 0;
}
i = 0;
for(i = 0 ; i < n-1 ;) {
while(array[i] == 0) {
i++;
}
array[i+0] = array[i+0]^divi[0];
array[i+1] = array[i+1]^divi[1];
array[i+2] = array[i+2]^divi[2];
array[i+3] = array[i+3]^divi[3];
array[i+4] = array[i+4]^divi[4];
}
for(i = n ; i < n+app ; i++) {
mess[i] = array[i];
}
printf("\n");
for(i = 0 ; i < n+app ; i++) {
printf("%d ",mess[i]);
}
printf("\n");
}
Also try this.........very compact and very simple to understand...........
To run this program just call this from your main function
like :-
main() {
crc();
}
By
Dixit Singla
void crc() {
int array[30] = {1,1,0,0,0,1,1,0,1,0,1,1,0,1,0,1};
int divi[10] = {1,0,0,1,1};
int mess[20];
int n = 16,d = 5,i;
int app = d-1;
for(i = 0 ; i < n ; i++ ) {
mess[i] = array[i];
}
for(i = 0 ; i < app ; i++) {
array[n+i] = 0;
}
i = 0;
for(i = 0 ; i < n-1 ;) {
while(array[i] == 0) {
i++;
}
array[i+0] = array[i+0]^divi[0];
array[i+1] = array[i+1]^divi[1];
array[i+2] = array[i+2]^divi[2];
array[i+3] = array[i+3]^divi[3];
array[i+4] = array[i+4]^divi[4];
}
for(i = n ; i < n+app ; i++) {
mess[i] = array[i];
}
printf("\n");
for(i = 0 ; i < n+app ; i++) {
printf("%d ",mess[i]);
}
printf("\n");
}
if(arr[i]==0)
{
for(j=i;j< g+i;++j)
arr[j] = arr[j]^0;
}
why this fun is required in CRC
if(arr[i]==0)
{
for(j=i;j< g+i;++j)
arr[j] = arr[j]^0;
}
why this fun is required in CRC
abe chutiye...bade input ke liya yeh work nahi karta
Bro, YOUR CRC CODE IS WRONG.PLEASE CHECK IT ONCE AGAIN AND UPDATE IT..
Post a Comment