{"record":{"id":"1a99d2bbc91b8d18","repo":"in3rsha/sha256-animation","slug":"we-only-operate-on-32-bit-words-in-sha-256-your-x","errorCode":null,"errorMessage":"We only operate on 32-bit words in SHA-256. Your x is #{ARGV[0].size} bits.","messagePattern":"We only operate on 32-bit words in SHA-256\\. Your x is #(.+?) bits\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rotr.rb","lineNumber":23,"sourceCode":"  mask = 2**32 - 1\n  right = (x >> n) & mask\n  left  = (x << 32-n) & mask\n  result = right | left\n  return result\nend\n\n# -----\n# Input\n# -----\n# defaults\nx = 0b11111111000000001111111100000000 #0b11101001101101011101101110100101\nn = 32\n# arguments passed\nx = ARGV[0].to_i(2) if ARGV[0] # binary\nn = ARGV[1].to_i    if ARGV[1] # integer\n# check arguments\nif ARGV[0] && ARGV[0].size > 32\n\tputs \"We only operate on 32-bit words in SHA-256. Your x is #{ARGV[0].size} bits.\"; exit\nend\n\n# ---------\n# Animation\n# ---------\ns = n.to_s.ljust(2, \" \")\nn.times do |i|\n  system \"clear\"\n  i += 1\n\n  puts \"      x: #{\"%032b\" % x}\"\n  puts \"ROTR #{s}: #{\"%032b\" % rotr(i, x)}\"\n\n  sleep 0.10\nend\nsleep 0.5\n\n","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/in3rsha/sha256-animation/blob/871e976d69e66474ef5239ee82031b7d87cbcafc/rotr.rb#L5-L41","documentation":"rotr.rb is a terminal animation of the 32-bit rotate-right (ROTR) operation used throughout SHA-256. It reads x from ARGV[0] via to_i(2), but first rejects any first argument longer than 32 characters, because SHA-256 words are exactly 32 bits. The check tests raw string length, not parsed bit width — so the two characters of an 0b prefix, leading zeros, or stray spaces all count toward the limit.","triggerScenarios":"ruby rotr.rb 111111110000000011111111000000001 (33 bits). Also a false positive: ruby rotr.rb 0b11111111000000001111111100000000 is a valid 32-bit word, but the prefix makes ARGV[0].size 34, so it is rejected even though to_i(2) would parse it correctly.","commonSituations":"Experimenting with words wider than 32 bits after computing message-schedule or compression values in irb (SHA-256 words are 32-bit, but intermediate big integers are not); passing 64-bit values; including the 0b prefix and tripping the undocumented character-count quirk.","solutions":["Trim x to its lowest 32 bits before passing it (x & 0xFFFFFFFF), or drop high bits from the left","Drop the 0b prefix when invoking the CLI — its 2 characters count against the 32-character limit, silently costing 2 bits of width","Compare against the built-in default word 11111111000000001111111100000000 (exactly 32 chars) to sanity-check length","Keep the rotation amount n (ARGV[1]) a plain decimal integer — it is independent of this width check"],"exampleFix":"# before\nruby rotr.rb 111111110000000011111111000000001    # 33 bits -> rejected\nruby rotr.rb 0b11111111000000001111111100000000  # prefix counted -> rejected\n\n# after\nruby rotr.rb 11111111000000001111111100000000     # exactly 32 bits, no prefix","handlingStrategy":"validation","validationCode":"x_arg = ARGV[0]\nraise ArgumentError, 'x must fit a 32-bit word' unless x_arg.nil? || x_arg.delete_prefix('0b').size <= 32\nsystem('ruby', 'rotr.rb', x_arg, '8')","typeGuard":"def fits_word32?(arg)\n  arg.nil? || arg.to_s.delete_prefix('0b').delete(' ').size <= 32\nend","tryCatchPattern":"begin\n  ARGV.replace([x_str, '8'])\n  load 'rotr.rb'\nrescue SystemExit\n  warn 'rotr.rb rejected x (argument longer than 32 characters)'\nend","preventionTips":["Truncate to 32 bits before animating: x & (2**32 - 1)","The check counts characters, not bits — omit the 0b prefix or budget its 2 characters","Keep the rotation amount (ARGV[1]) decimal and separate from the word width","Start from the built-in default 32-bit word, then change bits in place to stay within width"],"tags":["ruby","sha256","rotr","bit-manipulation","cli"],"backgroundTag":"word-size-exceeded","analyzedSha":"871e976d69e66474ef5239ee82031b7d87cbcafc","analyzedAt":"2026-08-23T12:17:23.862Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}