<commit_before>class RailFence
  
  # init 
  def initialize(key)
    @cipher=[]
    @decipher = []
    @cur_line=0
    @cur_line2=0
    @skip=0
    @key = key 
  end

  def encrypt(plain)
    plain = plain.gsub(" ", "") unless plain.nil?
    plain_len = plain.length

    # loop below 
    while @cur_line < @key-1 
      # below is the formula to get the number of skip
      @skip=2*(@key-@cur_line-1)
      
      # init
      j=0
      i=@cur_line

      # start looping row by row 
      while i < plain_len
        # push the current row first text to cipher array 
        @cipher.push(plain[i])
        # if the cuurrent number of row is even or current row is the first row, skip
        if (@cur_line==0 || j%2 == 0)
          i=i+@skip
        else 
          i=i+2*(@key-1)-@skip
        end
        # increase counter to check even or odd row 
        j=j+1
      end
      @cur_line=@cur_line+1
    end

    #loop below is to wrap the most bottom case
    i=@cur_line
    while i < plain_len
      @cipher.push(plain[i])
      i+=2*(@key-1)
    end
    
    # convert array to string
    @cipher = @cipher.join()
    # remove new line from string
    @cipher = @cipher.delete("\n")
    output = @cipher

    puts "Encrypted: " + output

    # puts "Encrpyted: " + output

    return output
  end

  def decrypt(cipher)
    # init (test)
    cipher_len = cipher.length
    m=0

    # start looping
    while @cur_line2 < @key-1 
      @skip=2*(@key-@cur_line2-1)
      n=@cur_line2
      l=0
      # start 2nd layer looping
      while n < cipher_len
        # skipped array equal to cipher array 0,1,2,3,m+1...
        @decipher[n]=cipher[m]
        m=m+1
        # if first n is equal to n+skip or if even number time of loop n+skip
        if (@cur_line2==0 || l%2 == 0)
          n=n+@skip
        else 
        # else if current line is odd
          n=n+2*(@key-1)-@skip
        end
        # increment of loop time
        l=l+1
      end
      # increment of 1st layer of loop
      @cur_line2=@cur_line2+1
    end

    # loop below is to wrap the most bottom case
    i=@cur_line2
    while i < cipher_len
      @decipher[i]= cipher[m]
      i+=2*(@key-1)
      m=m+1
    end
    @decipher = @decipher.join()
    output = @decipher

    puts "Decrypted: " + output

    # puts "Decrpyted: " + output

    return output
  end
end<commit_msg>Added rf comment<commit_after>class RailFence
  
  # init 
  def initialize(key)
    @cipher=[]
    @decipher = []
    @cur_line=0
    @cur_line2=0
    @skip=0
    @key = key 
  end

  def encrypt(plain)
    # remove whitespace
    plain = plain.gsub(" ", "") unless plain.nil?
    plain_len = plain.length

    # start encryption
    while @cur_line < @key-1 
      # below is the formula to get the number of skip
      @skip=2*(@key-@cur_line-1)
      
      # init
      j=0
      i=@cur_line

      # start looping row by row 
      while i < plain_len
        # push the current row i array of alpabet to cipher array 
        @cipher.push(plain[i])
        # if the cuurrent number of row is even or current row is the first row, skip
        if (@cur_line==0 || j%2 == 0)
          i=i+@skip
        else 
        # else i is next odd line of row 
          i=i+2*(@key-1)-@skip
        end
        # increase counter to check even or odd row 
        j=j+1
      end
      @cur_line=@cur_line+1
    end

    #loop below is to wrap the most bottom case
    i=@cur_line
    while i < plain_len
      # push the last row to cipher array 
      @cipher.push(plain[i])
      i+=2*(@key-1)
    end
    
    # convert array to string
    @cipher = @cipher.join()
    # remove new line from string
    @cipher = @cipher.delete("\n")
    output = @cipher

    puts "Encrypted: " + output

    # puts "Encrpyted: " + output

    return output
  end

  def decrypt(cipher)
    # init (test)
    cipher_len = cipher.length
    m=0

    # start looping
    while @cur_line2 < @key-1 
      @skip=2*(@key-@cur_line2-1)
      n=@cur_line2
      l=0
      # start 2nd layer looping
      while n < cipher_len
        # skipped array equal to cipher array 0,1,2,3,m+1...
        @decipher[n]=cipher[m]
        m=m+1
        # if first n is equal to n+skip or if even number time of loop n+skip
        if (@cur_line2==0 || l%2 == 0)
          n=n+@skip
        else 
        # else if current line is odd
          n=n+2*(@key-1)-@skip
        end
        # increment of loop time
        l=l+1
      end
      # increment of 1st layer of loop
      @cur_line2=@cur_line2+1
    end

    # loop below is to wrap the most bottom case
    i=@cur_line2
    while i < cipher_len
      @decipher[i]= cipher[m]
      i+=2*(@key-1)
      m=m+1
    end
    @decipher = @decipher.join()
    output = @decipher

    puts "Decrypted: " + output

    return output
  end
end
{'fraction_non_alphanumeric': 0.10548172757475083, 'fraction_numerical': 0.01951827242524917, 'mean_word_length': 1.8252199413489736, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836676', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1650, 'n_words': 497}