文件包含自己的校验和

zak*_*rya 49 security checksum data-integrity

是否可以创建一个包含自己的校验和(MD5,SHA1,无论如何)的文件?而对于沮丧的笑话,我的意思是普通的校验和,而不是计算它的函数.

Lat*_*SuD 33

我在C中创建了一段代码,然后运行了不到2分钟的暴力,并得到了这个奇迹:

The CRC32 of this string is 4A1C449B
Run Code Online (Sandbox Code Playgroud)

注意句子后面必须没有字符(行尾等).

你可以在这里查看:http://www.crc-online.com.ar/index.php?d = The + CRC32 + of+this+string+is+ 4A1C449B& en=Calcular+CRC32

这个也很有趣:

I killed 56e9dee4 cows and all I got was...
Run Code Online (Sandbox Code Playgroud)

源代码(对不起,有点乱)这里:http://www.latinsud.com/pub/crc32/


bri*_*gge 17

是.这是可能的,并且它与简单的校验和很常见.获取文件以包含它自己的md5sum将是非常具有挑战性的.

在最基本的情况下,创建一个校验和值,这将导致求和模数等于零.校验和函数就变成了类似的东西

(n1 + n2 ... + CRC) % 256 == 0
Run Code Online (Sandbox Code Playgroud)

如果校验和然后成为文件的一部分,并自行检查.一个非常常见的例子是信用卡号中使用的Luhn算法.最后一位是校验位,它本身是16位数字的一部分.

  • 这没有说明如何在文件中包含文件的md5sum,这就是问题所在. (9认同)

sas*_*sha 12

检查一下:

echo -e '#!/bin/bash\necho My cksum is 918329835' > magic
Run Code Online (Sandbox Code Playgroud)

  • 只需增加数字并通过bash脚本检查每秒约350次检查,持续3个月左右.我认为这不是这个文件唯一有效的cksum (11认同)

loc*_*ost 8

"我希望我的crc32是802892ef ..."

嗯,我觉得这很有趣所以今天我编写了一个小程序来查找碰撞.以为我会把它留在这里以防有人发现它有用:

import java.util.zip.CRC32;

public class Crc32_recurse2 {

    public static void main(String[] args) throws InterruptedException {

        long endval = Long.parseLong("ffffffff", 16);

        long startval = 0L;
//      startval = Long.parseLong("802892ef",16); //uncomment to save yourself some time

        float percent = 0;
        long time = System.currentTimeMillis();
        long updates = 10000000L; // how often to print some status info

        for (long i=startval;i<endval;i++) {

            String testval = Long.toHexString(i);

            String cmpval = getCRC("I wish my crc32 was " + testval + "...");
            if (testval.equals(cmpval)) {
                System.out.println("Match found!!! Message is:");
                System.out.println("I wish my crc32 was " + testval + "...");
                System.out.println("crc32 of message is " + testval);
                System.exit(0);
            }

            if (i%updates==0) {
                if (i==0) {
                    continue; // kludge to avoid divide by zero at the start
                }
                long timetaken = System.currentTimeMillis() - time;
                long speed = updates/timetaken*1000;
                percent =  (i*100.0f)/endval;
                long timeleft = (endval-i)/speed; // in seconds
                System.out.println(percent+"% through - "+ "done "+i/1000000+"M so far"
                        + " - " + speed+" tested per second - "+timeleft+
                        "s till the last value.");
                time = System.currentTimeMillis();
            }       
        }       
    }

    public static String getCRC(String input) {
        CRC32 crc = new CRC32();
        crc.update(input.getBytes());
        return Long.toHexString(crc.getValue());
    }

}
Run Code Online (Sandbox Code Playgroud)

输出:

49.825756% through - done 2140M so far - 1731000 tested per second - 1244s till the last value.
50.05859% through - done 2150M so far - 1770000 tested per second - 1211s till the last value.
Match found!!! Message is:
I wish my crc32 was 802892ef...
crc32 of message is 802892ef
Run Code Online (Sandbox Code Playgroud)

请注意,消息末尾的点实际上是消息的一部分.

在我的i5-2500上,需要大约40分钟才能从00000000到ffffffff搜索整个crc32空间,每秒进行大约180万次测试.它最大化了一个核心.

我对java很新,所以对我的代码有任何建设性意见.

"我的crc32是c8cb204,我得到的只是这件糟糕的T恤!"


Mar*_*som 7

当然,这是可能的.但校验和的一个用途是检测文件的篡改 - 如果修改文件也可以替换校验和,您如何知道文件是否已被修改?

  • @AmigableClarkKant,我的观点是走这条路是有害的 - 它首先打破了校验和的目的.这个问题特别提到了加密算法,所以我认为其意图是检测故意篡改而不是意外腐败. (3认同)

Ste*_*dit 5

当然,您可以将文件本身的摘要连接到文件末尾。要检查它,您将计算除最后一部分以外的所有内容的摘要,然后将其与最后一部分中的值进行比较。当然,没有某种形式的加密,任何人都可以重新计算摘要并替换它。

编辑

我要补充一点,这不是很不寻常。一种技术是连接CRC-32,以使整个文件(包括摘要)的CRC-32为零。但是,这不适用于基于加密哈希的摘要。