Skip to content

Instantly share code, notes, and snippets.

@matugm
Last active August 2, 2025 18:34
Show Gist options
  • Save matugm/db363c7131e6af27716c to your computer and use it in GitHub Desktop.
Save matugm/db363c7131e6af27716c to your computer and use it in GitHub Desktop.

Revisions

  1. matugm revised this gist Sep 6, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion caesar_3.rb
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ def caesar_cipher(string, shift = 1)

    encrypter = non_caps.merge(caps)

    string.chars.map { |c| encrypter.fetch(c, '?') }
    string.chars.map { |c| encrypter.fetch(c, c) }
    end

    p caesar_cipher("testingzZ1Z").join
  2. matugm revised this gist Jul 21, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion caesar_3.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    def caesar_cipher(string, shift = 1)
    alphabet = Array('a'..'z')
    non_caps = Hash[alphabet.zip(alphabet.rotate(shift))]
  3. matugm revised this gist Jul 21, 2015. 1 changed file with 14 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions caesar_3.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@

    def caesar_cipher(string, shift = 1)
    alphabet = Array('a'..'z')
    non_caps = Hash[alphabet.zip(alphabet.rotate(shift))]

    alphabet = Array('A'..'Z')
    caps = Hash[alphabet.zip(alphabet.rotate(shift))]

    encrypter = non_caps.merge(caps)

    string.chars.map { |c| encrypter.fetch(c, '?') }
    end

    p caesar_cipher("testingzZ1Z").join
  4. matugm revised this gist Jun 3, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions caesar_2.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    def caesar_cipher(string, shift = 1)
    alphabet = Array('a'..'z')
    encrypter = Hash[alphabet.zip(alphabet.rotate(shift))]
    string.chars.map { |c| encrypter[c] }
    encrypter = Hash[alphabet.zip(alphabet.rotate(shift))]
    string.chars.map { |c| encrypter.fetch(c, " ") }
    end

    p caesar_cipher("testing").join
  5. matugm revised this gist Jun 3, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions caesar_2.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    def caesar_cipher(string, shift = 1)
    alphabet = Array('a'..'z')
    @encrypter = Hash[alphabet.zip(alphabet.rotate(shift))]
    string.chars.map { |c| @encrypter[c] }
    encrypter = Hash[alphabet.zip(alphabet.rotate(shift))]
    string.chars.map { |c| encrypter[c] }
    end

    p caesar_cipher("testing").join
  6. matugm revised this gist Jun 3, 2015. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions caesar_2.rb
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    def caesar_cipher(string)
    def caesar_cipher(string, shift = 1)
    alphabet = Array('a'..'z')
    @encrypter = Hash[alphabet.zip(alphabet.rotate(1))]
    @encrypter = Hash[alphabet.zip(alphabet.rotate(shift))]
    string.chars.map { |c| @encrypter[c] }
    end

    p caesar_cipher("testing")
    p caesar_cipher("testing").join
  7. matugm revised this gist Mar 6, 2015. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion caesar_2.rb
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,3 @@

    def caesar_cipher(string)
    alphabet = Array('a'..'z')
    @encrypter = Hash[alphabet.zip(alphabet.rotate(1))]
  8. matugm revised this gist Mar 6, 2015. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions caesar_2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@

    def caesar_cipher(string)
    alphabet = Array('a'..'z')
    @encrypter = Hash[alphabet.zip(alphabet.rotate(1))]
    string.chars.map { |c| @encrypter[c] }
    end

    p caesar_cipher("testing")
  9. matugm created this gist Mar 6, 2015.
    17 changes: 17 additions & 0 deletions caesar.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    ALPHABET_SIZE = 26

    def caesar_cipher(string)
    shiftyArray = []
    charLine = string.chars.map(&:ord)

    shift = 1
    ALPHABET_SIZE.times do |shift|
    shiftyArray << charLine.map do |c|
    ((c + shift) < 123 ? (c + shift) : (c + shift) - 26).chr
    end.join
    end

    shiftyArray
    end

    puts caesar_cipher("testing")