חזור לתיקייה: גליון 1

Utilities

חיפוש בתיקיה
Ctrl K
לחץ כאן או הקש Ctrl K כדי לחפש בכל התיקיה

    Utilities

    02340124

    מבוא לתכנות מערכות

    רשימות הרצאה לקריאה בשבת

    Utilities

    הופק מתוך תקיית התואר של שקד

    uni-folder.vercel.app

    utilities.cpp

    הערה (קובץ קוד)

    קובץ זה הוא קובץ קוד מסוג CPP.

    
    #include <string>
    #include "Utilities.h"
    
    using std::string;
    
    
    string hash(int key, const string& value1, const string& value2) {
        static const int out_size = 20;
        char bytes[out_size + 1] = {0};
        for (int i = 0; i < out_size; i++) {
            bytes[i] = key ^ (out_size - i);
        }
        for (size_t i = 0; i < value1.size() * out_size ; i++) {
            bytes[i % (out_size/2)] ^= value1[i % value1.size()] ^ i;
        }
        for (size_t i = 0; i < value2.size() * out_size ; i++) {
            bytes[(out_size/2) + (i % out_size/2)] ^= value2[i % value2.size()] ^ i;
        }
        for (int i = 0; i < out_size; i++) {
            bytes[i] &= 0x0f;
            bytes[i] += (bytes[i] < 10) ? '0' : 'a' - 10;
        }
        return string(bytes);
    }
    
    
    string getErrorMessage() {
        return "Usage: ./mtm_blockchain <op> <source> <target> ";
    }