Skip to content

Instantly share code, notes, and snippets.

@Ninjex
Created May 11, 2016 21:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ninjex/40b80521bf850c04d6f9dfb78861ee6e to your computer and use it in GitHub Desktop.
Save Ninjex/40b80521bf850c04d6f9dfb78861ee6e to your computer and use it in GitHub Desktop.
Base64 Encode / Decode Script
def base64
@data = params[:data]
@choice = params[:choice]
if !["encode", "decode"].include?(@choice)
render :action => 'base64'
end
end
require 'base64'
<%= form_tag("/tools/base64", method: "post") do %>
<%= label_tag(:input, "Data:") %><br>
<% if @choice == "encode" %>
<%= select_tag(:choice, options_for_select({'Encode' => 'encode', 'Decode' => 'decode'}, 'decode')) %><br>
<%= text_area_tag(:data, Base64.encode64(@data)) %><br>
<% elsif @choice == "decode" %>
<%= select_tag(:choice, options_for_select({'Encode' => 'encode', 'Decode' => 'decode'}, 'encode')) %><br>
<%= text_area_tag(:data, Base64.decode64(@data)) %><br>
<% else %>
<%= select_tag(:choice, options_for_select({'Encode' => 'encode', 'Decode' => 'decode'})) %><br>
<%= text_area_tag(:data)%><br>
<% end %>
<%= submit_tag("Convert") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment