<commit_before>module CodeProcessor
	def decode decode_string,decode_hash
		decode_result = {}

		return unless check_string decode_string		# 检查字符串长度是否正确

		decode_hash.each do |name,info_hash|
			next if name == :resp_code						#收到数据不含有，响应码

			string_length = info_hash[:length]		
			if name == :card											#银行卡号不是固定的长度，需要用账户的长度减去电话号码的长度，计算得到
				string_length = decode_result[:account_len].to_i-decode_hash[:phone][:length]
			end

			#取得需要解码的string的长度
			string_temp = decode_string.slice!(0,string_length)
			if info_hash[:type] == :ascii_convert
				string_temp = ascii_to_string string_temp
			end

			#得到数据的名字，对应内容
			decode_result[name] = string_temp
		end

		decode_result[:trade_time].prepend decode_result[:trade_date]
		decode_result
	end


	def encode data_hash,encode_hash
		encode_string = ""

		data_hash[:trade_time] = data_hash[:trade_time].slice!(-6..-1)
		encode_hash.each do |name,info_hash|
			next if (name == :msg_len || (!data_hash.has_key? name))
			
			string_temp = data_hash[name]
			if info_hash[:type] == :ascii_convert
				string_temp = string_to_ascii string_temp
			end
			encode_string << string_temp
		end

		#add msg_length
		msg_length = encode_string.size.to_s(16).rjust(4,"0").upcase
		encode_string.insert(0,msg_length)

		encode_string
	end

	private

	def check_string decode_string
		return_bool = false
		return_bool = true if (decode_string.size.to_i == decode_string[0,4].hex.to_i+4)
		return_bool
	end<commit_msg>modified the decode and encode algorithm<commit_after>module CodeProcessor
	def decode decode_string,decode_hash
		decode_result = {}

		return unless check_string decode_string		# 检查字符串长度是否正确

		puts "not return"
		decode_hash.each do |name,info_hash|
			next if name == :resp_code						#收到数据不含有，响应码

			string_length = info_hash[:length]		
			if name == :card											#银行卡号不是固定的长度，需要用账户的长度减去电话号码的长度，计算得到
				string_length = decode_result[:account_len].to_i-decode_hash[:phone][:length]
			end


			#取得需要解码的string的长度
			string_temp = decode_string.slice!(0,string_length)

			case info_hash[:type]
			when :ascii_convert then
				string_temp = ascii_to_string string_temp
			when :bcd_byte then
				string_temp = string_temp.to_i*2	
			when :bcd_even then
				string_temp = string_temp[0,string_temp.size-1] if string_temp[-1] == "B"
			end
			
			#得到数据的名字，对应内容
			decode_result[name] = string_temp
		end

		decode_result[:trade_time].prepend decode_result[:trade_date]
		decode_result
	end


	def encode data_hash,encode_hash
		encode_string = ""

		data_hash[:trade_time] = data_hash[:trade_time].slice!(-6..-1)
		encode_hash.each do |name,info_hash|
			next if (name == :msg_len || (!data_hash.has_key? name))
			
			string_temp = data_hash[name]
			case info_hash[:type]
			when :ascii_convert then
				string_temp = string_to_ascii string_temp
			when :bcd_byte then
				string_temp = (string_temp.to_i/2).to_s	
			when :bcd_even then
				string_temp = string_temp.concat("B") if string_temp.size%2
			end
			encode_string << string_temp
		end

		#add msg_length
		msg_length = (encode_string.size/2).to_s(16).rjust(4,"0").upcase
		encode_string.insert(0,msg_length)

		encode_string
	end

	private

	def check_string decode_string
		return_bool = false
		puts "decode_string: #{decode_string.size.to_i}, calc: #{(decode_string[0,4].hex.to_i+4)*2}"
		return_bool = true if (decode_string.size.to_i == (decode_string[0,4].hex.to_i)*2+4)
		return_bool
	end
{'fraction_non_alphanumeric': 0.10093348891481914, 'fraction_numerical': 0.009918319719953326, 'mean_word_length': 4.316279069767442, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5858277', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1351, 'n_words': 227}