1
0
forked from kalmar/DALGLI0
DALGLI0/Decoding.java
Rafał Dąbkowski 17ff110b93 Prześlij pliki do ''
> Program uruchamia się z konsoli w sposób:
>
> java CRC ciąg_znaków_n-2 -e     //aby obliczyć FCS dla podanego ciąg
>
> java CRC ciąg_znaków_n -d        //aby sprawdzić czy ostanie suma kontrolna
> jest zgodna z treścią wiadomości
2018-06-25 16:56:44 +00:00

60 lines
1.7 KiB
Java

import java.util.ArrayList;
import java.util.Collections;
public class Decoding {
private Boolean check;
public Decoding(String arg){
Polynomials poly = new Polynomials(2);
ArrayList<Byte> message = new ArrayList<>();
ArrayList<Integer> g = new ArrayList<>();
ArrayList<Integer> l = new ArrayList<>();
ArrayList<Integer> tmp = new ArrayList<>();
ArrayList<Integer> tmp2 = new ArrayList<>();
for (int i = 0; i < arg.length(); ++i){
message.add((byte)arg.charAt(i));
}
for (int i = 0; i < 16; ++i){
if (i == 12 || i == 5 || i==0){
g.add(1);
} else{
g.add(0);
}
l.add(1);
}
g.add(1);
for (int i = 0; i < 16 ; ++i){
tmp.add(0);
}
for (byte b : message){
String s2 = String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
for (int i = 0; i < 8; ++i){
tmp2.add(Character.getNumericValue(s2.charAt(i)));
}
}
Collections.reverse(tmp2);
tmp.addAll(tmp2);
tmp2.clear();
for (int i = 0; i < arg.length() * 8; ++i) tmp2.add(0);
for (int i = 0; i < 16; ++i) tmp2.add(1);
tmp = poly.divModN(poly.add(tmp, tmp2),g);
if (tmp.size() == 0) {
check = true;
} else
check = false;
// String m = arg.substring(0, arg.length()-2);
// String fcs = arg.substring(arg.length()-2);
// Encoding e = new Encoding(m);
// if (e.getFcsChars().equals(fcs)) check = true;
// else check = false;
}
public Boolean getCheck() {
return check;
}
}