0
我正在使用Objective-C開發OSX應用程序,我需要做的事情之一是讀取在Windows機器上使用簡單位加密的text/xml文件移位算法。在Windows端加密代碼非常簡單,在德爾福:Objective-c:讀取在Windows上加密的文件
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;
問題是我無法弄清楚如何正確閱讀和解密這在Mac上側。我嘗試過使用NSData的各種方法,但沒有成功。
任何幫助或建議將不勝感激。
謝謝你的例子。我會花時間完成它,並得到結果,問題等。 – 2012-02-07 02:20:14
我終於有時間坐下來,讓它工作。你的代碼是一個很好的幫助。一張紙條;按位NOT運算符是**〜**不是**!**。代碼如下所示: NSMutableData * fileData = [NSMutableData dataWithContentsOfFile:dataPath]; UInt16 currentCipher = ????; unsigned char * bytes =(unsigned char *)malloc([fileData length]); [fileData getBytes:bytes];對於(int i = 0; i <[fileData length]; i ++){ bytes [i]^=〜(currentCipher >> i); } [fileData setData:[NSMutableData dataWithBytes:bytes length:[fileData length]]]; 再次感謝。 – 2012-02-12 21:04:37