Mesh Encryption
BlitzMax Forums/MiniB3D Module/Mesh Encryption| 
 | ||
| I'm trying to load a RC4 encrypted .b3d file from a bank. In TModel.bmx, the LoadAnimB3D method opens a stream like this - 
file=OpenStream("littleendian::"+f_name$)
My modification is as follows - 
'check for rc4 encryption
		If ExtractExt(f_name$).ToLower() = "b3dx"
			Local decrypted:String = RC4(LoadText(f_name$),RC4Key)
			Local bnk:TBank = LoadBank(decrypted)
			file=LittleEndianStream(CreateBankStream(bnk))
		Else
			file=OpenStream("littleendian::"+f_name$)
		EndIf
the RC4 method - Function RC4:String(inp:String, key:String) Local S:Int[512 + Ceil(inp.Length *.55)] Local i%, j%, t%, x% Local outbuf@@ Ptr = Short Ptr(Varptr s[512]) j = 0 For i = 0 To 255 S[i] = i If j > (Key.length-1) Then j = 0 EndIf S[256+i] = key[j]&$ff j:+ 1 Next j = 0 For i = 0 To 255 j = (j + S[i] + S[256+i]) & $ff t = S[i] S[i] = S[j] S[j] = t Next i = 0 j = 0 For Local x% = 0 To inp.Length-1 i = (i + 1) & $ff j = (j + S[i]) & $ff t = S[i] S[i] = S[j] S[j] = t t = (S[i] + S[j]) & $ff outbuf[x] = (inp[x] ~ S[t]) Next Return String.FromShorts(outbuf, inp.Length) End Function I've been wrestling with this all day and just can't seem to get it working :/ | 
| 
 | ||
| Got this to work, don't understand it but here it is: Local decrypted:String = RC4(LoadText(f_name$),RC4Key) Local bnk:TBank = New TBank Local bnkStr:TBankStream = TBankStream.Create(bnk) bnkStr.WriteBytes(decrypted.ToCString(),decrypted.length) file=LittleEndianStream(CreateBankStream(bnk)) |