ceol avatar ceol committed 96afea5

removed unnecessary shuffling of party data

Comments (0)

Files changed (1)

 
 import struct
 from array import array
-from pypkm.rng import Prng, Grng
+from pypkm.rng import Prng, Arng, Grng
 
 def checksum(data, size='H'):
     """Calculate the checksum of data using size as word-length.
     ]
     return ''.join(chunks)
 
-def _crypt(seed, data):
+def _crypt(seed, data, obj=Prng):
     """Encrypts/decrypts data with the given seed.
 
     Keyword arguments:
     """
 
     data = array('H', data)
-    lc = Prng(seed)
+    lc = obj(seed)
 
     new_data = array('H')
     for word in data:
     chksum = _checksum(box_data)
     box_data = _crypt(chksum, box_data)
 
-    party_data = _shuffle(pv, party_data)
     party_data = _crypt(pv, party_data)
 
     return _pack(pv, chksum, box_data, party_data)
     box_data = _unshuffle(pv, box_data)
 
     party_data = _crypt(pv, party_data)
-    party_data = _unshuffle(pv, party_data)
 
     return _pack(pv, chksum, box_data, party_data)
 
     Keyword arguments:
     data (string) -- the Pokémon data to encrypt
     """
-    pass
+    (pv, chksum, box_data, party_data) = _unpack(data)
+
+    box_data = _shuffle(pv, box_data)
+    chksum = _checksum(box_data)
+    box_data = _crypt(chksum, box_data, obj=Grng)
+
+    party_data = _crypt(pv, party_data, obj=Grng)
+
+    return _pack(pv, chksum, box_data, party_data)
 
 def decrypt_gts(data):
     """Decrypt PKM bin sent over the GTS.
     Keyword arguments:
     data (string) -- the Pokémon binary to decrypt
     """
-    pass
+    (pv, chksum, box_data, party_data) = _unpack(data)
+    
+    box_data = _crypt(chksum, box_data, obj=Grng)
+    box_data = _unshuffle(pv, box_data)
+
+    party_data = _crypt(pv, party_data, obj=Grng)
+
+    return _pack(pv, chksum, box_data, party_data)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.