Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6383095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:36:24+00:00 2026-05-25T02:36:24+00:00

Apparently this used to work on ruby 1.8.7 but unfortunately not on 1.9.2 class

  • 0

Apparently this used to work on ruby 1.8.7 but unfortunately not on 1.9.2

class String
  def xor(key)
    text = dup
    text.length.times {|n| text[n] ^= key[n.modulo key.size] }
    text
  end
end

def encode(_original, _pass = 'testvendor')
  _original.xor(_pass)
end

puts encode('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.')

#output=>    
8
EE
DEBDREBDEVSR
TTTT
TNZV0D
SE E    CRVSETENR   D

TT
    EKS0DSO VD
EVVTE S 
RSREXE+E T
 RR
T _TOEDE RO E
TTD
K

It returns

NoMethodError: undefined method `^' for "V":String

Any idea on how to get this working?

Thanks a lot

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:36:24+00:00Added an answer on May 25, 2026 at 2:36 am

    In 1.8, the String#[] method returned a Fixnum which was the byte at the specified index. In newer version, String#[] returns a String because strings are made of characters and the character-to-byte mapping depends on the encoding. Looks like you’re using a String as a byte buffer so you should be working in Array instead of String:

    class Array
      def xor(key)
         a = dup
         a.length.times { |n| a[n] ^= key[n % key.size] }
         a
      end
    end
    

    And then to use it:

    mangled_array = string.codepoints.to_a.xor(key.codepoints.to_a)
    

    Then if you really want a String (which will contain a bunch of unprintable control characters and zero bytes and such things), then:

    mangled_string = mangled_array.inject('') { |s,c| s << c }
    

    And then to unpack:

    mangled_string.
      codepoints.
      to_a.
      xor(key.codepoints.to_a).
      inject('') { |s,c| s << c }
    

    All of this should maintain UTF-8 all the way through and that’s what you want.

    You could probably patch your xor into Enumerable and skip the to_a business if desired. You could probably also adapt this to patch for String as well.

    You shouldn’t be using String for byte buffers anymore, you’re better off using arrays of Fixnum for that with explicit encoding handling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function which used to work, but apparently decided to take a
Apparently, this does not work. WHY ??????? I don't want to do all this
This code used to work on Vista (and Windows XP) but after an upgrade
This is a very basic question - but apparently google is not very good
Apparently this is very basic jQuery but im on a time crunch and I
Trying to parse some XML but apparently this is too much for a lazy
I see the CSC task in NAnt has a nowarn attribute, but apparently this
I'm being passed an object that returns System.Byte[*] when converted to string. This apparently
I have this sql: ALTER TABLE dbo.ChannelPlayerSkins DROP CONSTRAINT FK_ChannelPlayerSkins_Channels but apparently, on some
I am creating an ajax login and it used to work but for some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.