Delphi - Ayudita con algoritmo verhoeff

 
Vista:

Ayudita con algoritmo verhoeff

Publicado por Ireneo (12 intervenciones) el 07/01/2009 17:42:02
Hola amigos como están, yo después de un tiempito estoy otra ves con una dudita espero que puedan ayudarme

Bueno
El problema es que necesito generar un codigo de control con el algoritmo verhoeff y no tengo ni la menor idea de cómo funciona, si alguien tiene echo este código en delhpi por favor echen me una manito

De ante mano les agradezco mucho


Saludas
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 65
Oro
Ha mantenido su posición en Delphi (en relación al último mes)
Gráfica de Delphi

RE:Ayudita con algoritmo verhoeff

Publicado por E.T. (1244 intervenciones) el 08/01/2009 01:56:05
Intenté traducir el ejemplo que está en php a delphi, que se encuentra en wikipedia, pero no se si esté bien

Codigo de la form, abre un archivo de texto y pega este codigo, lo guardas con extención dfm, mas abajo está el codigo fuente

object Form1: TForm1
Left = 253
Top = 165
Width = 297
Height = 201
Caption = 'verhoeff'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 16
Top = 16
Width = 37
Height = 13
Caption = 'Numero'
end
object Label2: TLabel
Left = 16
Top = 80
Width = 48
Height = 13
Caption = 'Resultado'
end
object Edit1: TEdit
Left = 72
Top = 8
Width = 121
Height = 21
TabOrder = 0
Text = '123456'
end
object Button1: TButton
Left = 24
Top = 40
Width = 75
Height = 25
Caption = 'calcsum'
TabOrder = 1
OnClick = Button1Click
end
object Button2: TButton
Left = 104
Top = 40
Width = 75
Height = 25
Caption = 'checksum'
TabOrder = 2
OnClick = Button2Click
end
object Edit2: TEdit
Left = 72
Top = 72
Width = 121
Height = 21
TabOrder = 3
end
end

//********************************************************************************
//********************************************************************************
//********************************************************************************
Este es el codigo de la unidad, el archivo pas

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, strutils;

type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Label2: TLabel;
Edit2: TEdit;
function d(j, k:integer):integer;
function p(pos, num:integer):integer;
function inv(j:integer):integer;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

function TForm1.d(j, k:integer): integer;
var sal:integer;
const d : array[0..9] of array[0..9] of integer = (
(0,1,2,3,4,5,6,7,8,9),
(1,2,3,4,0,6,7,8,9,5),
(2,3,4,0,1,7,8,9,5,6),
(3,4,0,1,2,8,9,5,6,7),
(4,0,1,2,3,9,5,6,7,8),
(5,9,8,7,6,0,4,3,2,1),
(6,5,9,8,7,1,0,4,3,2),
(7,6,5,9,8,2,1,0,4,3),
(8,7,6,5,9,3,2,1,0,4),
(9,8,7,6,5,4,3,2,1,0));
begin
sal := d[j][k];
result := sal;
end;

function TForm1.inv(j:integer): integer;
var sal:integer;
const i : array[0..9] of integer = (0,4,3,2,1,5,6,7,8,9);
begin
sal := i[j];
result := sal;
end;

function TForm1.p(pos, num:integer): integer;
var sal:integer;
const p : array[0..7] of array[0..9] of integer = (
(0,1,2,3,4,5,6,7,8,9),
(1,5,7,6,2,8,3,0,9,4),
(5,8,0,3,7,9,6,1,4,2),
(8,9,1,6,0,4,3,5,2,7),
(9,4,5,3,1,2,6,8,7,0),
(4,2,8,6,5,7,3,9,0,1),
(2,7,9,3,8,0,6,4,1,5),
(7,0,4,6,9,1,3,2,5,8));
begin
sal := p[pos {mod 8}][num];
//return $table[$pos % 8][$num];
result := sal;
end;

procedure TForm1.Button1Click(Sender: TObject);
var c, len, i:integer;
n:string;
begin
c := 0;

n := ReverseString(Edit1.Text);

len := length(n);
for i:= 0 to len-1 do
c := d(c, p(i+1, strtoint(n[i+1])));

Edit2.Text := inttostr(inv(c));
end;

procedure TForm1.Button2Click(Sender: TObject);
var c, len, i:integer;
n:string;
begin
c := 0;

n := ReverseString(Edit1.Text);

len := length(n);
for i:= 0 to len-1 do
c := d(c, p(i+1, strtoint(n[i+1])));

Edit2.Text := inttostr((c));
end;

end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Ayudita con algoritmo verhoeff

Publicado por Ireneo (12 intervenciones) el 08/01/2009 16:20:54
Hola E.T. muchas gracias por ayudarme
Todavía no lo he probado pero te cuento luego

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar