kod dönüştürme

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
ikutluay
Üye
Mesajlar: 2341
Kayıt: 03 Tem 2007 10:13

kod dönüştürme

Mesaj gönderen ikutluay »

Kod: Tümünü seç

        private string Decode(byte[] data, ref int offset)
        {
            byte[] decodedData;
            int stringLength = data[offset] | (data[offset + 1] << 8) | (data[offset + 2] << 16) | (data[offset + 3] << 24);
            offset += 4;
            if (stringLength < 32768) //sanity check
            {
                decodedData = new byte[stringLength];
                uint modWord = 0x0816;
                for (int i = 0; i < stringLength; i++)
                {
                    byte encodedByte = data[i + offset];
                    uint tmpModWord = modWord;
                    byte decodedByte = 0;

                    tmpModWord &= 0xff00;
                    tmpModWord = tmpModWord >> 8;
                    decodedByte = (byte)(tmpModWord ^ encodedByte);
                    tmpModWord = encodedByte;
                    tmpModWord += modWord;
                    tmpModWord = tmpModWord & 0xffff; //eliminate overflow
                    tmpModWord = tmpModWord * 0x6081;
                    tmpModWord = tmpModWord & 0xffff; //eliminate overflow
                    tmpModWord += 0x1608;
                    tmpModWord = tmpModWord & 0xffff; //eliminate overflow
                    modWord = tmpModWord;

                    decodedData[i] = decodedByte;
                }
            }
            else
            {
                throw new Exception(String.Format("String too long: {0}", stringLength));
            }
            offset += stringLength;
            //convert the data to a string now and then return it
            return System.Text.ASCIIEncoding.ASCII.GetString(decodedData);
        }
Merhaba

yukardaki kodu delphi türevi olarak yapılışını sormuş bir arkadaşım. merakıma mucip oldu. Arada bir fırsat buldukça csharp a bakmaya çalışıyorum. işin tuhafı c++ koldarını çevirmekte daha az sıkıntı yaşamıştım.

bir yere kadar getirdim ama tıkandım.
Kişi odur ki, koyar dünyada bir eser. Eseri olmayanın yerinde yeller eser./Muhammed Hadimi
http://www.ibrahimkutluay.net
http://www.ibrahimkutluay.net/blog
Kullanıcı avatarı
SimaWB
Üye
Mesajlar: 1316
Kayıt: 07 May 2009 10:42
Konum: İstanbul
İletişim:

Re: kod dönüştürme

Mesaj gönderen SimaWB »

Emin olmamakla birlikte belki yararı olur diyerek :)

Kod: Tümünü seç

function Decode(data: array of byte; var offset: integer): string;
var
  decodedData: array of byte;
  i, stringLength: integer;
  modWord, tmpModWord:longword;
  encodedByte, decodedByte: byte;
begin
  stringLength := data[offset] or (data[offset + 1] shl 8) or (data[offset + 2] shl 16) or (data[offset + 3] shl 24);
  offset := offset + 4;
  if (stringLength < 32768) then//sanity check
  begin
    SetLength(decodedData, stringLength);
    modWord := $0816;
    for i := 0 to stringLength-1 do
    begin
      encodedByte := data[i + offset];
      tmpModWord  := modWord;
      decodedByte := 0;

      tmpModWord := tmpModWord AND $ff00;
      tmpModWord := tmpModWord SHR 8;
      decodedByte := byte(tmpModWord XOR encodedByte);
      tmpModWord := encodedByte;
      tmpModWord := tmpModWord + modWord;
      tmpModWord := tmpModWord AND $ffff; //eliminate overflow
      tmpModWord := tmpModWord * $6081;
      tmpModWord := tmpModWord AND $ffff; //eliminate overflow
      tmpModWord := tmpModWord + $1608;
      tmpModWord := tmpModWord AND $ffff; //eliminate overflow
      modWord := tmpModWord;

      decodedData[i] := decodedByte;
    end;
  end
  else
    raise Exception.Create(Format('String too long: %d', [stringLength]));

  offset := offset + stringLength;
  //convert the data to a string now and then return it
  SetString(Result, PAnsiChar(@decodedData[0]), stringLength);
end;
Not: Tabiki kullanımını denemedim :D
There's no place like 127.0.0.1
ikutluay
Üye
Mesajlar: 2341
Kayıt: 03 Tem 2007 10:13

Re: kod dönüştürme

Mesaj gönderen ikutluay »

bunu üzerinden deneme yanılma bakarım artık
Kişi odur ki, koyar dünyada bir eser. Eseri olmayanın yerinde yeller eser./Muhammed Hadimi
http://www.ibrahimkutluay.net
http://www.ibrahimkutluay.net/blog
Cevapla