동기
TCP/IP를 공부하다가 TCP Header에서 Checksum을 이용하여 넘어온 바이트를 검사하는 방식을 알게 되었다. 그러다가 문득 내 친구의 말이 생각났다.
우리 회사 코드를 만약 수정하면 바로 서비스 올 스톱이야
신기하지 않냐?
그래서 보니 Checksum 방식이 이와 매우 유사한 것 같았다
만들어 보기
두 개의 파일은 동일하다. 단 한 가지 다른 부분은 hack.txt 에 제일 마지막 문자는 스페이스가 하나 들어가 있다.
위의 체크섬이 원본이다.
public class Test {
public static void main(String[] args) throws IOException {
BufferedReader actReader = new BufferedReader(new InputStreamReader(new FileInputStream("src/main/resources/test.txt")));
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/main/resources/hack.txt")));
long[] acts = actReader
.lines()
.map(String :: getBytes)
.mapToLong(Test :: getCRC32CheckSum)
.toArray();
long[] hacks = reader
.lines()
.map(String :: getBytes)
.mapToLong(Test :: getCRC32CheckSum)
.toArray();
System.out.println(Arrays.toString(acts));
System.out.println(Arrays.toString(hacks));
}
public static long getCRC32CheckSum(byte[] bytes){
Checksum checksum = new CRC32();
checksum.update(bytes, 0, bytes.length);
return checksum.getValue();
}
}
Java
복사
결론
가정을 해봤다. 파일로 화이트 스페이스가 들어간 부분 때문에 checksum이 다르다. 그렇다면 class 파일도 되지 않을까? 그럼 내 코드를 건드는 사람을 찾아 낼 수 있을 것 같다.