Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:38:13+00:00 2026-06-11T02:38:13+00:00

I have the following test application: import Codec.Crypto.AES import qualified Data.ByteString.Char8 as B key

  • 0

I have the following test application:

import Codec.Crypto.AES
import qualified Data.ByteString.Char8 as B

key = B.pack "Thisismykey....."

iv = B.pack "0000000000000001"

main = do 
     let myenc = crypt' CTR key iv Encrypt (B.pack "1234567812345678") 
     print (B.unpack myenc)

That prints the following result:
“\250\DC4\DC4\255\223\221C\ETBx\239sF\nuZu”

If I change the cleartext “1234567812345678” into “1234567812345688”
I get “\250\DC4\DC4\255\223\221C\ETBx\239sF\nuUu”

If I change the cleartext to “1134567812345678”
I get the output “\250\ETB\DC4\255\223\221C\ETBx\239sF\nuZu”

I am now very surprised since there is clearly a predictable correlation between the input and the output that IMHO should not happen. If I change something at the front of the cleartext then only the front of the output is affected etc.. Can it be that somehow has to do with 8 or 16 Byte boundaries of byte strings and how could I fix this? Is something misguiding me here?

Independent from the CTR mode it should be noticed that AES works with 4×4 byte arrays and the question is about the encryption of a single array. AES should to my understanding perform four rounds of mixing and the change of a single byte (out of 16) should result in at least 50% of the bits being different. Thus, it can in my opinion not be that changes at the end of a 16 byte cleartext change exactly the end of the cipher text and changes at the front change the front etc.. To my understanding the IV only comes into play as a counter when multiple 4×4 arrays are involved.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:38:14+00:00Added an answer on June 11, 2026 at 2:38 am

    It has nothing to do with haskell.

    Read http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Initialization_vector_.28IV.29

    Since you are using the same IV to encrypt the message twice under CTR mode it is not secure.
    Read about cryptography algorithms and try to avoid writing your own crypto code as it is more likely to have security loopholes.

    The requirement of CTR mode is (key,IV) pair should be unique.
    The trivial solution would be generate a new IV for every new message you encrypt.

    [explanation of CTR mode security flaw]
    https://crypto.stackexchange.com/questions/2991/why-must-iv-key-pairs-not-be-reused-in-ctr-mode

    In CTR mode F(IV+counter,key) XOR Plaintext = CIPHER .. so if nonce and key remain same then F is same for both the plain text .. So If $C_1$ is cipher of $P_1$ and $C_2$ is cipher of $P_2$ then

    xor($C_1$,$C_2$) = xor($P_1$,$P_2$) for same (key,IV) pair
    

    Supporting code :

    import Codec.Crypto.AES
    import qualified Data.ByteString.Char8 as B
    import qualified Data.ByteString as BS
    import Data.Bits (xor) 
    
    key = B.pack "Thisismykey....."
    
    iv = B.pack "1234567891012131"
    p1 =  (B.pack "1234567812345678") 
    p2 =  (B.pack "1234567812345688") 
    x = crypt' CTR key iv Encrypt p1 
    y = crypt' CTR key iv Encrypt p2 
    
    main = do 
         print $ BS.zipWith xor x y  
         print $ BS.zipWith xor p1 p2
    

    Output

    [0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0]
    [0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following test case in my iOS application : -(void) testTwoDefaultUsersExist {
Work on this small test application to learn threading/locking. I have the following code,
I have the following Python (3.2) code: from pygame import * class Application: def
I have following test.pyx cdef public class Foo[object Foo, type FooType]: cdef public char*
I have following test class @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {/services-test-config.xml}) public class MySericeTest { @Autowired
suppose I have following test/ Main.py test/one/ One.py test1.txt test/two/ Two.py test2.txt What I
I have following databases: test table1 fields: id, password, name, lastname test2 table2 fields:
I have following string: Test, User < test@test.com >, Another, Test < another@test.com >,
I have the following test case: @ContextConfiguration(/spring/test-context.xml) @TransactionConfiguration(transactionManager=txManager) @Transactional() public class MyEntityDaoTestCase extends AbstractJUnit4SpringContextTests
For my test I have the following: test should update holder do holder =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.