哪位高手能把这段磁卡读写 do S_C 程序转换成Delphi程序,感谢万分。!!!(终于上传程序正常显示.浪费了200分了。) (100分)

A

apower

Unregistered / Unconfirmed
GUEST, unregistred user!
#include<float.h>
#include<graph.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<time.h>
#include <math.h>
#include <conio.h>
#include <stdarg.h>
/*#include "头.h"*/
short int i,cmprslt;
char buffer[65],code1[11],code2[11],code3[11],code4[11],key;
char table1[15],table2[15],table3[15],table4[15],data1[11],data2[11];
char data3[11],temp[7],temp1[5],temp3[5],temp4[5];
unsigned long ll;
unsigned long temp2;
size_t len1,len2;
char menu();
char *decard1();
main()
{
char ch2,ch3,ch1;
_setvideomode(_VRES16COLOR);
/* logon(0);
demo1();*/
loop:
ch1=menu();
switch (ch1)
{
case '1': /*prt_pass()*/;break;
case '2': wr_cable();break;
case '3': return(1);
};
goto loop;
};
char menu()
{
char ch;
_setvideomode(_VRES16COLOR);
_settextwindow(2,4,25,78);
_wrapon(_GWRAPON);
_settextcolor(14);
_settextposition(3,26);
_outtext("证子管理信息系统");
_settextposition(5,33);
_outtext("微机制证子菜单");
_settextposition(8,20);
_outtext("※※※※※※※※※※※※※※※※※※※※");
_settextposition(9,20);
_outtext("※ ※");
_settextcolor(14);
_settextposition(10,20);
_outtext("※ 请选择: ※");
_settextposition(11,20);
_outtext("※ ※");
_settextposition(12,20);
_outtext("※ 打 卡 ---------------1 ※");
_settextposition(13,20);
_outtext("※ ※");
_settextposition(14,20);
_outtext("※ 写 磁 条 ---------------2 ※");
_settextposition(15,20);
_outtext("※ ※");
_settextposition(16,20);
_outtext("※ 退 出 ---------------3 ※");
_settextposition(17,20);
_outtext("※ ※");
_settextposition(18,20);
_outtext("※※※※※※※※※※※※※※※※※※※※");
ch=getch();
return(ch);
}

wr_cable()
{
int di;
int len4,len5;
char yn,dataa[11];
char data4[11];
char test[11];
_setvideomode(_VRES16COLOR);
_settextwindow(2,4,25,78);
_wrapon(_GWRAPON);
loop:
_clearscreen(_GWINDOW);
_settextcolor(14);
_settextposition(7,10);
_outtext("/n 请输入编号(0-9999999999): /n");
scanf("%10s",data1);
len1=strlen(data1);
if (len1!=10)
{_outtext("/n 输入有错 ! ");
goto loop;
}

lp1: _settextposition(10,10);
_outtext("/n 请再输入一遍: /n");
scanf("%10s",data2);
len2=strlen(data2);
if (len2!=10)
{_outtext("/n 输入有错! /n");
goto lp1;
}
data1[10]='/0';
data2[10]='/0';
cmprslt=strcmp(data1,data2);
if(cmprslt!=0)
{_outtext("/n 输入有错! 请重新确认!/n");
goto loop;
}
_settextposition(17,20);
_outtext("/n 输入正确 ! /n");

loop2:
strcpy(dataa,data1);
strcpy(table1,"ASWFLKGJXM");
strcpy(table2,"KDFWZHUIAN");
strcpy(table3,"7463820915");
strcpy(table4,"3210485796");
for(i=0;i<=9;i++)
{
di=toascii(data1)-48;
code1=table1[di];
code2=table2[di];
code3=table3[di];
code4=table4[di];
}
for(i=0;i<65;i++)
buffer='/0';
buffer[0]='/02';
buffer[1]='%';
strcat(buffer,code1);
strcat(buffer,code2);

buffer[22]='?';
buffer[23]=';';
strcat(buffer,code3);
strcat(buffer,code4);
buffer[44]='?';
strcat(buffer,"+670518920608?/03");
_clearscreen(_GWINDOW);
wrcard(buffer);
_settextposition(5,20);
_outtext("检验: 请将写好的磁卡扫过读卡机");
strcpy(test,decard1());
test[10]='/0';
_settextposition(8,20);
_outtext("磁卡内容是:");
_outtext(test);
getch();
/*------------------*/
dataa[10]='/0';
strncpy(temp,dataa,6);
temp[6]='/0';
strcpy(temp1,dataa+6);

temp1[4]='/0';
temp2=atol(temp1);
temp2++;
/* ultoa(temp2,temp3,4);*/
sprintf(temp3,"%ld",temp2);

len4=strlen(temp3);
temp3[len4]='/0';
len5=4-len4;
for (i=0;i<len5;i++)
temp4='0';
temp4[len5]='/0';
strcat(temp4,temp3);
strcat(temp,temp4);
temp[10]='/0';

strcpy(data4,temp);


/*------------------*/
/* ll=atol(dataa);
ll++;
ultoa(ll,data3,10);

len4=strlen(data3);
data3[len4]='/0';
len5=10-len4;
for (i=0;i<len5;i++)
data4='0';
data4[len5]='/0';
strcat(data4,data3);
*/
_settextposition(15,20);
_outtext("/n下一个编号是:");
_outtext(data4);
_outtext("吗?(y/n)");
yn=getch();
if (yn=='y')
{ strcpy(data1,data4);
data1[10]='/0';
data4[10]='/0';
goto loop2;}
if (yn=='n')
goto loop;
}

//******* 另外再请高手写一个读卡程序,即请一个卡号解码 ******
//已知一卡号为:6001234567,
//它划卡后显示为:%GAASWFLKGJUKKDFWZHUI?;07746382095332104857?

 
终于能看到了,可能有些字符不能上传!!!
 
有一个简单的方法,安装一个Port Mon,然后运行这个程序,从Port Mon上就可以看到程序
向串口写入了哪些内容,然后一切都好办了。
 
Port Mon 是什么东西,请赐教!
 
其中loop2:那里应该是加密的,如何转成delphi,不懂!!
 
一开始没看你前面的数据类型,你自己改一下吧,大致如下:


function decard1():string;
begin
end;

procedure loop2;
const
table1='ASWFLKGJXM';
table2='KDFWZHUIAN';
table3='7463820915';
table4='3210485796';

var
dataa,data1,data4,data3,test,temp,temp1,temp3:string ;
i,di,temp2,len4,len5,ll:integer;
code1,code2,code3,code4,buffer,temp4:array[0..255] of char;
begin
//loop2:
dataa:=data1;
for i:=0 to 9 do
begin
di:=ord(data1[i+1])-48;
code1:=table1[di+1];
code2:=table2[di+1];
code3:=table3[di+1];
code4:=table4[di+1];
end;
for i:=0 to 64 do buffer:=#0;
buffer[0]:=#2;
buffer[1]:='%';
strcat(buffer,code1);
strcat(buffer,code2);

buffer[22]:='?';
buffer[23]:=';';
strcat(buffer,code3);
strcat(buffer,code4);
buffer[44]:='?';
strcat(buffer,'+670518920608?'#3);

// _clearscreen(_GWINDOW);
// wrcard(buffer);
// _settextposition(5,20);
// _outtext("检验: 请将写好的磁卡扫过读卡机");
showmessage('检验: 请将写好的磁卡扫过读卡机');
test:=decard1();
test[11]:=#0;
// _settextposition(8,20);
// _outtext("磁卡内容是:");
// _outtext(test);
// getch();
// /*------------------*/
showmessage('磁卡内容是:'+test);

dataa[11]:=#0;
temp:=copy(dataa,1,6);
temp[7]:=#0;
temp1:=string(@dataa[7]);

temp1[5]:=#0;
temp2:=strtoint(temp1);
inc(temp2);
// /* ultoa(temp2,temp3,4);*/
// sprintf(temp3,"%ld",temp2);
temp3:=format('%d',[temp2]);
len4:=length(temp3);
temp3[len4+1]:=#0;
len5:=4-len4;
for i:=0 to len5 do temp4:=#0;
strcat(temp4,@temp3[1]);
strcat(@temp[1],temp4);
temp[10]:=#0; // 11
data4:=temp;

ll:=strtoint(dataa);
inc(ll);
data3:=inttostr(ll);
len4:=length(data3);
data3[len4]:=#0;
len5:=10-len4;
for i:=0 to len5 do data4:=#0;
strcat(@data4[1],@data3[1]);

{
_settextposition(15,20);
_outtext("/n下一个编号是:");
_outtext(data4);
_outtext("吗?(y/n)");
yn=getch();
if (yn=='y')
strcpy(data1,data4);
data1[10]='/0';
data4[10]='/0';
goto loop2;
if (yn=='n')
goto loop;
}
end;
 
strcpy(test,decard1());
这里还缺少一个decard1函数
其实也没什么,只是感觉中间做那么复杂的工作,好象没有什么必要
 
decard和wrcard是POS机上附带的连接程序,是用来读写磁条的。写磁条时,必须对输入的卡号进行加密。然后使用wrcard;读磁条时必须使用decard,他已经内置了解密的程式。
其他就没什么了,都是一些显示用的代码。
 
把语法转换一下即可。工作量应不大。我做的通讯程序就是c和delphi通用的。把{}替换begin end。。
 
jsxjd,的办法好象不太行吧,能具体吗?
 
试试这个?
之后的代码似乎是在校验什么然后为下一张卡片作准备的。

procedure TForm1.Button1Click(Sender: TObject);
var
di,i:Integer;
TempStr1,TempStr2:String;
TempData,test:String;
Table1,Table2,Table3,Table4:String;
Code1,code2,code3,code4:String;
Buffer:String;
Begin
TempStr1:=Edit1.Text;
TempStr2:=Edit2.Text;
If (TempStr1<>TempStr2) Or (Length(TempStr1)<>10) Then
Begin
showmessage('data length error');
Exit;
End;

TempData:=TempStr1;
table1:='ASWFLKGJXM';
table2:='KDFWZHUIAN';
table3:='7463820915';
table4:='3210485796';
code1:='';code2:='';code3:='';code4:='';
for i:=1 To 10 Do
Begin
di:=StrToInt(Copy(TempStr1,i,1));
If di=0 Then
di:=10;
code1:=code1+Copy(table1,di,1);
code2:=code2+Copy(table2,di,1);
code3:=code3+Copy(table3,di,1);
code4:=code4+Copy(table4,di,1);
End;
buffer:='';
buffer:=#2;
buffer:=Buffer+'%';
buffer:=Buffer+code1;
buffer:=Buffer+code2;
buffer:=Buffer+'?';
Buffer:=Buffer+';';
buffer:=Buffer+code3;
buffer:=Buffer+code4;
buffer:=Buffer+'?';
buffer:=Buffer+'+670518920608?'+#3;
// wrcard(pchar(buffer));
showmessage('检验: 请将写好的磁卡扫过读卡机');
// test:=decard1();
If Test=TempStr1 Then
Showmessage('OK');
end;
 
我手头上没有decard和wrcard是写磁卡附带的连接程序,哪位好心人能帮助解决一下!!
 
用wcode方法解码6001234567
解码为:%KMMASWFLKGHNNKDFWZHU?;25574638208663210485?+670518920608?
正确为:%GAASWFLKGJUKKDFWZHUI?;07746382095332104857?
 
你是要转换成 DELPHI 程序还是 PASCAL 程序?
应该不是很难 -------- 只是太繁而已。

strcpy -> strcopy
strcmp -> strcomp
...

一个一个代下去...

其中的 loop: 转换成 label, 简单是简单,就是太繁,
无能为力了[^]
 
用wcode方法解码6001234567
解码为:%KMMASWFLKGHNNKDFWZHU?;25574638208663210485?+670518920608?
正确为:%GAASWFLKGJUKKDFWZHUI?;07746382095332104857?


从结果上看,正确的应该是table1:='ASWFLKGJXM';
table2:='KDFWZHUIAN';
table3:='7463820915';
table4:='3210485796';
解码解错了,俺是从1-10,它是从0-9而已,看看码制就知道了。没有嘛问题的。至于那两个函数,俺可无能为力了,俺从来没有玩过磁卡,不过想来也没有什么难的,我用的都是IC卡。
 
有人能做一个读卡程序吗?
 
俺[:)]报名先
 
这个程序太简单了,只是一个数据加密或解密的过程,不同的写卡机的写卡方式是不一样的
 
顶部