CRC32 간단 예제 - java

jino630·2021년 6월 16일
0

hash

목록 보기
6/6
        {
            String str = "jino630";
            byte[] bytes = str.getBytes(StandardCharsets.UTF_8);

            CRC32 crc32 = new CRC32();
            crc32.update(bytes);
            long checksum1 = crc32.getValue();

            String str2 = "HelloWorld";
            byte[] bytes2 = str2.getBytes(StandardCharsets.UTF_8);

            crc32.reset();

            crc32.update(bytes2);
            long checksum2 = crc32.getValue();

            assert (checksum1 != checksum2);

            String str3 = "jino630";
            byte[] bytes3 = str3.getBytes(StandardCharsets.UTF_8);

            crc32.reset();

            crc32.update(bytes3);
            long checksum3 = crc32.getValue();

            assert (checksum1 == checksum3);
        }

0개의 댓글