Base64 Encode Decode in Ruby

Published on 14 May 2026 (Updated: 14 May 2026)

Welcome to the Base64 Encode Decode in Ruby page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

# frozen_string_literal: true

require "base64"

USAGE = "Usage: please provide a mode and a string to encode/decode"

mode, input = ARGV

abort(USAGE) if mode.nil? || input.nil? || input.strip.empty?

case mode
when "encode"
  puts Base64.strict_encode64(input)

when "decode"
  begin
    puts Base64.strict_decode64(input)
  rescue
    abort(USAGE)
  end

else
  abort(USAGE)
end

Base64 Encode Decode in Ruby was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.