Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > C++ Builder
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

 
 
Herramientas Buscar en Tema Desplegado
  #18  
Antiguo 05-03-2020
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.141
Poder: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola a todos,

Aquí los intentos que llevo a cabo, usando tanto el código de escafandra como el de ecfisa, dando ambos el mismo resultado: 22586, pero, no el esperado: 5320, la madre que le parió.

Código Delphi [-]
function StrToBytes(const Value: string): TBytes;
var
  I: integer;
begin
  SetLength(Result, Length(Value));
  Move(Value[1], Result[0], Length(Value));
end;

function WordToBytes(const Value: Word): TBytes;
begin
 SetLength(Result, 2);
 Result[0] := TBytes(@Value)[0];
 Result[1] := TBytes(@Value)[1];
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  x, z: Word;
  crc: Word;
  count, i: Integer;
  Input: string;
  Data, Result: TBytes;
begin
  Input := '13|0000123|1|Maximilian|Mustermann|05051999|21092019';
  
  Data := StrToBytes(Input);

  x := 0;
  crc := $1D0F;
  count := Pred(Length(Data));
  while (count >= 0) do
  begin
    Dec(count);
    Inc(x);
    z   := Word(Data[x]) shl 8;
    crc := crc xor z;
    for i := 7 downto 0 do
      if crc and $8000 <> 0 then
        crc := (crc shl 1 xor $1021)
      else
        crc := (crc shl 1);
  end;

  Result := WordToBytes(crc);

  ShowMessageFmt('%d%d', [Result[0], Result[1]]);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  S: TBytes;
  i, x: Integer;
  z: WORD;
  CRC: WORD;
  SLength, n: Integer;
  Result: TBytes;
  Input: string;
begin
  Input := '13|0000123|1|Maximilian|Mustermann|05051999|21092019';

  S := StrToBytes(Input);

  CRC := $1D0F;
  SLength := Length(S);
  X := 1;
  while SLength > 0 do
  begin
    Z := S[X] shl 8;
    CRC := CRC xor Z;
    i:= 8;
    repeat
      if (CRC and $08000) <> 0 then
        CRC := (CRC shl 1) xor $1021
      else
        CRC := (CRC shl 1);
      dec(i);
    until i <= 0;
    Inc(X);
    Dec(SLength);
  end;

  Result := WordToBytes(CRC);

  ShowMessageFmt('%d%d', [Result[0], Result[1]]);
end;
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Ayuda para Convertir Todo este código en Function MaxiDucoli Internet 3 01-10-2017 22:29:07
Convertir cadena aleatoria en cadena de N caracteres DANY OOP 3 12-03-2009 20:49:21
Problemas para validar entrada de datos en delphi 7 Nelly Varios 1 27-03-2007 23:31:25
Tengo un lio con cierto código David OOP 11 13-10-2006 20:07:34
Concatenar Cadena Larga dentro de codigo Delphi JoanKa Conexión con bases de datos 6 04-03-2005 17:53:44


La franja horaria es GMT +2. Ahora son las 12:35:58.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi