Decrypting an encrypted aes 256 cbc text with random IV, decrypts the string

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












This may be a basic question but bear with me.



I started encrypting a text with aes 256 cbc mode generating a random iv of 16 bytes and a key.



text = 'hi I am learning encryption.';


Then I created another random iv and tried to decrypt the encrypted text. ( I know we are supposed to use the same iv we used for encryption to decrypt the ciphered text).



The result came as



(some rubbish text) encryption.


Then I padded the main text with 16 random characters, encrypted it and decrypted it I get my actual text padded with some junk text at the start.



I am unable to figure out why it messes with the first 16 bytes of text and then successfully extracts the remaining.



Can you explain?










share|improve this question









New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
    – dave_thompson_085
    53 mins ago














up vote
1
down vote

favorite












This may be a basic question but bear with me.



I started encrypting a text with aes 256 cbc mode generating a random iv of 16 bytes and a key.



text = 'hi I am learning encryption.';


Then I created another random iv and tried to decrypt the encrypted text. ( I know we are supposed to use the same iv we used for encryption to decrypt the ciphered text).



The result came as



(some rubbish text) encryption.


Then I padded the main text with 16 random characters, encrypted it and decrypted it I get my actual text padded with some junk text at the start.



I am unable to figure out why it messes with the first 16 bytes of text and then successfully extracts the remaining.



Can you explain?










share|improve this question









New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



















  • Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
    – dave_thompson_085
    53 mins ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite











This may be a basic question but bear with me.



I started encrypting a text with aes 256 cbc mode generating a random iv of 16 bytes and a key.



text = 'hi I am learning encryption.';


Then I created another random iv and tried to decrypt the encrypted text. ( I know we are supposed to use the same iv we used for encryption to decrypt the ciphered text).



The result came as



(some rubbish text) encryption.


Then I padded the main text with 16 random characters, encrypted it and decrypted it I get my actual text padded with some junk text at the start.



I am unable to figure out why it messes with the first 16 bytes of text and then successfully extracts the remaining.



Can you explain?










share|improve this question









New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











This may be a basic question but bear with me.



I started encrypting a text with aes 256 cbc mode generating a random iv of 16 bytes and a key.



text = 'hi I am learning encryption.';


Then I created another random iv and tried to decrypt the encrypted text. ( I know we are supposed to use the same iv we used for encryption to decrypt the ciphered text).



The result came as



(some rubbish text) encryption.


Then I padded the main text with 16 random characters, encrypted it and decrypted it I get my actual text padded with some junk text at the start.



I am unable to figure out why it messes with the first 16 bytes of text and then successfully extracts the remaining.



Can you explain?







aes cbc initialization-vector






share|improve this question









New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 5 hours ago





















New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 5 hours ago









Suman Lama

1085




1085




New contributor




Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Suman Lama is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











  • Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
    – dave_thompson_085
    53 mins ago
















  • Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
    – dave_thompson_085
    53 mins ago















Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
– dave_thompson_085
53 mins ago




Dupe crypto.stackexchange.com/questions/1129/… (2011) and crypto.stackexchange.com/questions/2865/… (2012)
– dave_thompson_085
53 mins ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Here is the picture for CBC decryption ($oplus$ is the XOR operation of each bit/byte at the same position of the input blocks):



enter image description here



As you can see only the first block is altered by the IV.



During encryption every block is changed because the ciphertext will propagate the uniqueness of the IV over all subsequent blocks. However, during decryption only the first block is XOR'ed with the IV to get back the first block of plaintext.



If that block is random then the result will also be random. The rest of the blocks is unaffected.



If you change just a single bit of the original IV, then only that particular bit in the plaintext block will be affected.






share|improve this answer






















  • Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
    – Suman Lama
    3 hours ago










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "281"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Suman Lama is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcrypto.stackexchange.com%2fquestions%2f62626%2fdecrypting-an-encrypted-aes-256-cbc-text-with-random-iv-decrypts-the-string%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Here is the picture for CBC decryption ($oplus$ is the XOR operation of each bit/byte at the same position of the input blocks):



enter image description here



As you can see only the first block is altered by the IV.



During encryption every block is changed because the ciphertext will propagate the uniqueness of the IV over all subsequent blocks. However, during decryption only the first block is XOR'ed with the IV to get back the first block of plaintext.



If that block is random then the result will also be random. The rest of the blocks is unaffected.



If you change just a single bit of the original IV, then only that particular bit in the plaintext block will be affected.






share|improve this answer






















  • Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
    – Suman Lama
    3 hours ago














up vote
3
down vote



accepted










Here is the picture for CBC decryption ($oplus$ is the XOR operation of each bit/byte at the same position of the input blocks):



enter image description here



As you can see only the first block is altered by the IV.



During encryption every block is changed because the ciphertext will propagate the uniqueness of the IV over all subsequent blocks. However, during decryption only the first block is XOR'ed with the IV to get back the first block of plaintext.



If that block is random then the result will also be random. The rest of the blocks is unaffected.



If you change just a single bit of the original IV, then only that particular bit in the plaintext block will be affected.






share|improve this answer






















  • Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
    – Suman Lama
    3 hours ago












up vote
3
down vote



accepted







up vote
3
down vote



accepted






Here is the picture for CBC decryption ($oplus$ is the XOR operation of each bit/byte at the same position of the input blocks):



enter image description here



As you can see only the first block is altered by the IV.



During encryption every block is changed because the ciphertext will propagate the uniqueness of the IV over all subsequent blocks. However, during decryption only the first block is XOR'ed with the IV to get back the first block of plaintext.



If that block is random then the result will also be random. The rest of the blocks is unaffected.



If you change just a single bit of the original IV, then only that particular bit in the plaintext block will be affected.






share|improve this answer














Here is the picture for CBC decryption ($oplus$ is the XOR operation of each bit/byte at the same position of the input blocks):



enter image description here



As you can see only the first block is altered by the IV.



During encryption every block is changed because the ciphertext will propagate the uniqueness of the IV over all subsequent blocks. However, during decryption only the first block is XOR'ed with the IV to get back the first block of plaintext.



If that block is random then the result will also be random. The rest of the blocks is unaffected.



If you change just a single bit of the original IV, then only that particular bit in the plaintext block will be affected.







share|improve this answer














share|improve this answer



share|improve this answer








edited 1 hour ago

























answered 4 hours ago









Maarten Bodewes

48.2k567179




48.2k567179











  • Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
    – Suman Lama
    3 hours ago
















  • Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
    – Suman Lama
    3 hours ago















Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
– Suman Lama
3 hours ago




Thank you. It actually makes good sense now. I guess I hadn't understood the encryption step better. I missed the fact that during encryption only first block is XOR-ed with IV.
– Suman Lama
3 hours ago










Suman Lama is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Suman Lama is a new contributor. Be nice, and check out our Code of Conduct.












Suman Lama is a new contributor. Be nice, and check out our Code of Conduct.











Suman Lama is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcrypto.stackexchange.com%2fquestions%2f62626%2fdecrypting-an-encrypted-aes-256-cbc-text-with-random-iv-decrypts-the-string%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

Long meetings (6-7 hours a day): Being “babysat” by supervisor

Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

Confectionery