我一直试图用102的第一个字节和加密头的最后一个字节来强制ZipCryptoKey2,看看需要多长时间,但我得到了2000多个有效密钥. 在APPNOTE中,Key2用于解密字节,Key2106的结果,这意味着它是一个应该在107107*109范围内找到的32位值.

此测试流的密码为

1234

CRC,

77D7DCDE

然后是流:

50 4B 03 04 14 00 01 00 08 00 68 99 6D 58 DE DC D7 77 CB 82 07 00 0F B1 0A 00 09 00 00 6B 65 79 73 30 2E 74 78 74 50 3F 83 D5 C7 D4 69 6E 9B B9 E9 F2 DD 16 D5 EA 5B 41 F9 BC 59 6E 34 E8 2F 2B 49 4E DD 90 3E D8 65 5E 21 42 E6 8C 8C AD 8E

下面是代码示例:

#ifdef LINUX

#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>

typedef pthread_t thread;
typedef pthread_mutex_t mutex;

static inline void mutex_init(mutex *m)
{
    int res = pthread_mutex_init(m, NULL);
    assert(res == 0);
}

static inline void mutex_lock(mutex *m)
{
    int res = pthread_mutex_lock(m);
    assert(res == 0);
}

static inline void mutex_unlock(mutex *m)
{
    int res = pthread_mutex_unlock(m);
    assert(res == 0);
}

static thread spawn_thread(void *(f)(void *), void *arg)
{
    thread t;
    int res = pthread_create(&t, NULL, f, (void *)arg);
    if (res != 0)
        return (thread)NULL;
    return t;
}

static void join_thread(thread t)
{
    pthread_join(t, NULL);
}

static size_t num_threads(void)
{
    return (size_t)sysconf(_SC_NPROCESSORS_ONLN);
}


static uint64_t get_time(void)
{
    struct timespec ts;
    clock_gettime(CLOCK_MONOTONIC, &ts);
    return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
}

#endif


unsigned char decrypt_byte(size_t Key2) {
    uint32_t dkey = Key2;
    unsigned short temp = dkey | 2;
    return (temp * (temp ^ 1)) >> 8;
}


static bool bytecheck(const unsigned char dat)
{
    unsigned char targ = 0x77;//first byte of my Checksum
    
    if(dat == targ)
       {
            return true;
        }
    return false;
}


struct info
{
    unsigned char buffer;
    size_t start;
    size_t end;
};

// Stop when a thread finds a solution.
static volatile bool stop = false;
static void *worker(void *arg);

static thread spawn_worker( size_t start, size_t end, unsigned char buffer)
{
    struct info *info = (struct info *)malloc(sizeof(struct info));
    assert(info != NULL);
    info->start = start;
    info->end = end;
    info->buffer = buffer;
    thread t = spawn_thread(worker, info);
    if (t == (thread)NULL)
    {
        fprintf(stderr, "error: failed to spawn thread");
        exit(EXIT_FAILURE);
    }
    return t;
}
static void *worker(void *arg)
{
    struct info *info = (struct info *)arg;
    size_t start = info->start;
    size_t end = info->end;
    unsigned char buf = info->buffer;
    free(info);
    for(size_t i =start; i < end+1; i++)
    {
        if (stop)
            return NULL;
        unsigned char res = decrypt_byte(i);
        unsigned char C = buf ^ res;

        if (bytecheck(C))
        {
            printf("%zu\n",i);
            stop = true;
            return NULL;
        }
    }

}

//gcc ben.c -pg --std=gnu99 -lz -lm -lpthread -o zipcr

int main()
{

    size_t NUM_WORKERS = num_threads();
    printf("threads = %lu\n", NUM_WORKERS);
    uint64_t t0 = get_time();
    size_t tap = 2147483648;
    size_t port = tap / NUM_WORKERS;
    thread ts[NUM_WORKERS];
    for (size_t i = 0; i < NUM_WORKERS; i++)
        {
            size_t start = tap+ (i*port);
            size_t end = start+port;
            unsigned char buffer = 0xF2;
            ts[i] = spawn_worker(start, end,buffer);
        }
        for (size_t i = 0; i < NUM_WORKERS; i++)
            join_thread(ts[i]);
    uint64_t t1 = get_time();
    printf("\ntime = %lums\n", t1 - t0);

return 0;
}

为什么我得到这么多假阳性,我的代码有什么问题?

推荐答案

所有这些都可以归结为:

#include <stdio.h>

int main(void) {
    size_t tap = 2147483648;
    for (size_t i = tap; i < 2 * tap + 1; i++) {
        unsigned short temp = i | 2;
        unsigned char ch = 0xf2 ^ ((temp * (temp ^ 1)) >> 8);
        if (ch == 0x77)
            printf("%zu\n", i);
    }
    return 0;
}

不过,我go 掉了"Stop",这样所有结果都会打印出来.(顺便说一句,这在我的机器上运行大约两秒钟,所以我不知道所有线程的意义是什么.)

这将打印8388608个结果,即迭代次数的1/256(减1).当判断随机生成的一个字节时,这正是您所期望的.这里没有什么令人惊讶的.你在期待什么?

然而,在231个 case 上运行它(由于某种原因加上一个)没有意义,因为查询的输入只有16位(短)!实际上,| 2之后只有15位.您只需要32768次迭代就可以探索函数的整个域.

C++相关问答推荐

问关于C中的指针和数组

是否可以在C中进行D3 D12申请?

如何确保内存分配在地址附近?

如何避免使用相对路径包含在c中

如何启用ss(另一个调查套接字的实用程序)来查看Linux主机上加入的多播组IP地址?

在32位处理器上优化53—32位模计算>

如果我释放其他内容,返回值就会出错

为什么删除CAP_DAC_OVERRIDE后创建文件失败?

GDB输出ARM助记符

如何在C中使数组变量的值为常量?

强制转换变量以在 struct 中蚕食

为什么用非常数指针变量改变常量静态变量时会出现分段错误?

为什么未初始化的 struct 的数组从另一个数组获取值?

如何使用唯一数字对整型进行分区

如何在C++中安全地进行浮点运算

这段代码用于在C中以相反的顺序打印数组,但它不起作用

程序对大输入给出错误答案

我错误地修复了一个错误,想了解原因

在列表中查找素数

如何根据当前舍入方向将float转换为int?