I encrypted numerical value as following.
> secret = Sestrong textcureRandom::hex(128)
> encryptor = ::ActiveSupport::MessageEncryptor.new(secret, cipher: 'aes-256-cbc')
> message1 = 1
> encrypt_message1 = encryptor.encrypt_and_sign(message1)
> message2 = 10000
> encrypt_message2 = encryptor.encrypt_and_sign(message2)
> message3 = 1000000000000000000000000000
> encrypt_message3 = encryptor.encrypt_and_sign(message3)
There are multiple layers to what is happening here, and you cannot explain it solely on the data size + encryption used (ie you have to factor in the transformations that happen also)
and after that look at: https://github.com/rails/rails/blob/29be3f5d8386fc9a8a67844fa9b7d6860574e715/activesupport/lib/active_support/message_verifier.rb which is used in the encryptor.
There are a few stages:
If you want to understand the generated encrypted data you basically need to trace through the code above, but:
::Base64.strict_encode64(Marshal.dump(1)).size is 8 ::Base64.strict_encode64(Marshal.dump(10000)).size is 8 ::Base64.strict_encode64(Marshal.dump(1000000000000000000000000000)).size is 24
Marshal.dump(1).size is 4 Marshal.dump(10000).size is 6 Marshal.dump(1000000000000000000000000000).size is 17
Here is how Marshal.dump works internally: http://jakegoulding.com/blog/2013/01/15/a-little-dip-into-rubys-marshal-format/
Here is how base64 encoding works: https://blogs.oracle.com/rammenon/entry/base64_explained Look at the rules for padding.