fix login issue*
This commit is contained in:
54
test/test_shanda.exs
Normal file
54
test/test_shanda.exs
Normal file
@@ -0,0 +1,54 @@
|
||||
# Test Shanda cipher - encrypt then decrypt should give original
|
||||
|
||||
Code.require_file("lib/odinsea/util/bit_tools.ex", ".")
|
||||
Code.require_file("lib/odinsea/net/cipher/shanda_cipher.ex", ".")
|
||||
|
||||
alias Odinsea.Net.Cipher.ShandaCipher
|
||||
alias Odinsea.Util.BitTools
|
||||
|
||||
import Bitwise
|
||||
|
||||
# Test with simple data
|
||||
data = <<0x01, 0x00, 0x07, 0x70, 0x00, 0x04, 0x00>>
|
||||
IO.puts("Original data: #{Base.encode16(data)}")
|
||||
|
||||
# Encrypt
|
||||
encrypted = ShandaCipher.encrypt(data)
|
||||
IO.puts("Encrypted: #{Base.encode16(encrypted)}")
|
||||
|
||||
# Decrypt
|
||||
decrypted = ShandaCipher.decrypt(encrypted)
|
||||
IO.puts("Decrypted: #{Base.encode16(decrypted)}")
|
||||
|
||||
IO.puts("Match: #{data == decrypted}")
|
||||
IO.puts("")
|
||||
|
||||
# If they don't match, let's debug step by step
|
||||
if data != decrypted do
|
||||
IO.puts("MISMATCH! Let's debug...")
|
||||
IO.puts("")
|
||||
|
||||
# Manual encrypt - first pass only
|
||||
bytes = :binary.bin_to_list(data)
|
||||
data_len = length(bytes)
|
||||
data_length = data_len &&& 0xFF
|
||||
|
||||
IO.puts("Data length: #{data_len}")
|
||||
IO.puts("Initial bytes: #{inspect(bytes)}")
|
||||
IO.puts("")
|
||||
|
||||
# First pass (j=0, forward)
|
||||
IO.puts("=== Pass 0 (forward) ===")
|
||||
{result0, remember0} = Enum.reduce(Enum.with_index(bytes), {[], 0}, fn {cur, i}, {acc, remember} ->
|
||||
cur = BitTools.roll_left(cur, 3)
|
||||
cur = (cur + data_length) &&& 0xFF
|
||||
cur = bxor(cur, remember)
|
||||
new_remember = cur
|
||||
cur = BitTools.roll_right(cur, data_length &&& 0xFF)
|
||||
cur = bxor(cur, 0xFF)
|
||||
cur = (cur + 0x48) &&& 0xFF
|
||||
{[cur | acc], new_remember}
|
||||
end)
|
||||
result0 = Enum.reverse(result0)
|
||||
IO.puts("After pass 0: #{inspect(result0)}, remember: #{remember0}")
|
||||
end
|
||||
Reference in New Issue
Block a user