Skip to content

documentation of line 139 and following in Cipher.cpp #1

@josephpal

Description

@josephpal

Encrypting a whole string with variable length needs splitting it into buffers of 16 characters. The encrypted result consists of each buffer, which has to be encrypted separately.

for(int block=0; block < plainText.length()/BUFF_SIZE; block++) {
     for(int j = block*BUFF_SIZE; j < (block+1)*BUFF_SIZE; j++) {
          buffer += plainText[j];
     }

     cipherTextString += encryptBuffer(const_cast<char*>(buffer.c_str()), key);
     buffer = "";
}

buffer="";

if( plainText.length()%BUFF_SIZE > 0 ) {    
     for(int bytes_read=(index*BUFF_SIZE); bytes_read <= (index*BUFF_SIZE) + plainText.length()%BUFF_SIZE; bytes_read++) {
     buffer += plainText[bytes_read];
     };

     cipherTextString += encryptBuffer(const_cast<char*>(buffer.c_str()), key);
}

return cipherTextString;```

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions