@@ -49,11 +49,19 @@ public static String modifyMessage(String message, String polynomial) {
49
49
return message ;
50
50
}
51
51
52
+ // Passing Through Noisy Channel
53
+ public static String noisyChannel (String msgToBeTransmitted ) {
54
+ StringBuilder noise = new StringBuilder (msgToBeTransmitted );
55
+ noise .setCharAt (msgToBeTransmitted .length ()/2 , '1' );
56
+ String noisyData = noise .toString ();
57
+ return noisyData ;
58
+ }
59
+
52
60
53
61
public static void main (String [] args ) {
54
62
Scanner sc = new Scanner (System .in );
55
63
System .out .print ("Enter the Data(Message) to be Encrypted: " ); // Original Message
56
- String message = sc .next (); // Test --> 1010000
64
+ String message = sc .next (); // Test --> 1010000 , 100100111
57
65
58
66
System .out .print ("Enter the CRC Generator(Polynomial): " ); // CRC Generator
59
67
String polynomial = sc .next (); // Test --> 1001
@@ -64,19 +72,19 @@ public static void main(String[] args) {
64
72
String msgToBeTransmitted = generateCRC_CheckBits (modified_message , polynomial );
65
73
System .out .println ("\n Data(Message) is ready to be Transmitted: " + msgToBeTransmitted );
66
74
67
- System . out . print ( "Enter the Data(Message) to be Transmitted: " );
68
- String send_data = sc . next ( );
75
+ String send_data = noisyChannel ( msgToBeTransmitted );
76
+ System . out . println ( "Data(Message) Transmitted through Noisy Channel: " + send_data );
69
77
70
78
String checkAllZeroes = xorOperation (send_data ,polynomial );
71
79
72
80
// It checks if the remainder contains only zeroes --> If it contains only zeros then the data/message is accepted else considered as error in Transmission
73
81
for (int i = 0 ; i < checkAllZeroes .length (); i ++) {
74
82
if (checkAllZeroes .charAt (i ) == '1' ) {
75
- System .out .println ("Error in Transmission!" );
83
+ System .out .println ("\n Error in Transmission!\n " );
76
84
return ;
77
85
}
78
86
}
79
87
80
- System .out .println ("No! Error in Transmission! " );
88
+ System .out .println ("\n Data(Message) Transmitted Successfully! \n " );
81
89
}
82
90
}
0 commit comments