DES with CBC

Hi! Does anybody know DES with CBC about? I have some code but it is very big. It Is some part of DES with CBC:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//ENCRYPTION PHASE
    int round=16;
    while(round--) {
        rightTerm = right;
        t = 1;
        std::string expansionP = "", xorOperation = "", sout = "" , sBoxOutput;
        expansionP += right[31];
        for(int i = 0; i < 32; i++) {
            if((t + 1) % 6 == 0) {
                expansionP += right[4*((t + 1) / 6)];
                t++;
            }
            if(t % 6 == 0 && i!=0) {
                expansionP+=right[4*(t/6)-1];
                t++;
            }
            expansionP = expansionP + right[i];
            t++;
        }
        expansionP += right[0];
        //XOR
        for(int i = 0; i < 48; i++) xorOperation += char(((int(expansionP[i]) - 48) ^ key[16 - round - 1][i]) + 48);
        //sbox compression
        for(int i = 0; i < 48; i += 6) {
            row = (int(xorOperation[i+5]) - 48) + (int(xorOperation[i]) - 48) * 2;
            col = (int(xorOperation[i+1]) - 48) * 8 + (int(xorOperation[i+2])-48) * 4 + (int(xorOperation[i + 3]) - 48) * 2  + (int(xorOperation[i + 4]) - 48);
            temp=s[i / 6][row][col];
            sBoxOutput = "";
            while(temp > 0) {
                sBoxOutput += char(temp % 2 + 48);
                temp /= 2;
            }
            while(sBoxOutput.length() != 4) sBoxOutput += '0';
            for(int j = sBoxOutput.length() - 1; j >= 0; j--) sout += sBoxOutput[j];
        }

        char pc[32];
        for(int i = 0; i < 32; i++) pc[i]=sout[per[i]-1];
        right = "";
        for(int i = 0; i < 32; i++) right+=char(((int(pc[i])-48)^(int(left[i])-48))+48);
        left = rightTerm;
        std::cout << "Output after Round" << 16 - round << std::endl;
        std::string cipher = "";
        for(int i = 0; i < 32; i += 4) {
            int te;
            te=(int(left[i])-48)*8+(int(left[i+1])-48)*4+(int(left[i+2])-48)*2+(int(left[i+3])-48);
            if(te<10) cipher+=char(te+48);
            else cipher+=char(te+55);
        }
        for(int i=0;i<32;i+=4) {
            int te;
            te=(int(right[i])-48)*8+(int(right[i+1])-48)*4+(int(right[i+2])-48)*2+(int(right[i+3])-48);
            if(te<10) cipher+=char(te+48);
            else cipher+=char(te+55);
        }
        result = cipher;
        cipherTextBlock[k] = result;
        std::cout << cipher << std::endl; //FOR diagnosis
    }
        std::cout<<"The encrypted message is: ";
        for(int i=0;i<len;i++) std::cout<<cipherTextBlock[i];
    }
    std::cout << std::endl;
    system( "read -n 1 -s -p 'Press any key to Decrypt...'; echo" );
for (int k=0;k<len;k++){
    left=hexToBin(cipherTextBlock[k]).substr(0,32);
    right=hexToBin(cipherTextBlock[k]).substr(32,32);
    std::cout<<"Decrypt piece #"<<k+1<<std::endl;  //For Diagnosis 
Last edited on
Is there a question here?
Yes.
Does anybody know DES with CBC about?
Maybe anybode have a good code of this.
github.com has code. Good code? May be.
https://github.com/search?l=C%2B%2B&q=DES+CBC&type=Repositories
Off hand, DES is so insecure that triple DES (running it 3 times) is required for normal use, you're probably required to use 3DES rather than DES.

You have the XOR required by CBC, but I don't see those questionable constants the NSA defined. I'll take a more detailed look later today, I'll have to lookup the algorithm to verify what you've done, it's been a while.
Off hand, DES is so insecure that triple DES (running it 3 times) is required for normal use, you're probably required to use 3DES rather than DES.

Even Triple-DES is deprecated by NIST and ENISA.
https://csrc.nist.gov/news/2017/update-to-current-use-and-deprecation-of-tdea
https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-131Ar2.pdf
See Table 1 of the latter.
Topic archived. No new replies allowed.