I am working on an OSX application using Objective-C, and one of the things I need to do is read text/xml files which were encrypted on a Windows machine using a simple bit-shift algorithm. The encryption code on the Windows side is fairly simple, in Delphi:
const
EncryptKey : word = ????;
var
InMS : TMemoryStream;
cnt : Integer;
c : byte;
begin
InMS := TMemoryStream.Create;
result := TMemoryStream.Create;
try
InMS.LoadFromFile( FileName );
InMS.Position := 0;
for cnt := 0 to InMS.Size - 1 do
begin
InMS.Read( c, 1 );
c := ( c xor not ( ord( EncryptKey shr cnt ) ) );
result.Write( c, 1 );
end;
finally
InMS.Free;
end;
end;
The problem is I can’t figure out how to properly read and decrypt this on the Mac side. I’ve tried various approaches to using NSData with no success whatsoever.
Any help or suggestions would be greatly appreciated.
May be this would help you (simple xor encrypting):
here:
currentCipheris your EcrytpKey,^xor. also shift right in C is>>, not operator is!.