69,373
社区成员
发帖
与我相关
我的任务
分享
#define LAWLESS(code) (code==0x2e||code==0x22 || code==0x2a ||code==0x2b || code==0x2c || \
code==0x3a || code==0x3b || code==0x3c ||code==0x3d || code==0x3e || code==0x3f ||\
code==0x5b || code==0x5c || code==0x5d || code==0x7c)
#define NUM(code) (code>=0x30&&code=<0x39)
#define LETTER(code) ((code>0x41&&code<=0x5a)||(code>0x61&&code<=0x7a))
#define SJIS_SINGER(code) (code>=0xa1&&code<=0xdf)
#define SJIS_SIGN(code) (code>0x8140&&code<0xeaa4)
int isprint(unsigned short sjiscode)
{
for(int i=0;i<6;i++)
{
if(sjiscode>=codesection[i].from&&sjiscode<=codesection[i].to)
return 0;
}
return -1;
}
if(isprint(code)) // isprint的返回值为1和-1,条件判断永远为真了
typedef struct
{
unsigned short from;
unsigned short to;
}SCODESECTION;
SCODESECTION codesection[6]={
{0x8140,0x81fc},{0x824f,0x83d6},{0x8440,0x84be},
{0x8740,0x879c},{0x889f,0x9ffc},{0xe040,0xeaa4}
};
#define LAWLESS(code) (code==0x2e||code==0x22 || code==0x2a ||code==0x2b || code==0x2c || code==0x2f || \
code==0x3a || code==0x3b || code==0x3c ||code==0x3d || code==0x3e || code==0x3f || \
code==0x5b || code==0x5c || code==0x5d || code==0x7c) \
#define NUM(code) (code>=0x30&&code=<0x39)
#define LETTER(code) ((code>0x41&&code<=0x5a)||(code>0x61&&code<=0x7a))
#define SJIS_SINGER(code) (code>=0xa1&&code<=0xdf)
#define SJIS_SIGN(code) (code>0x8140&&code<0xeaa4)//((code>0x8140&&code<0x817e)||(code>0x8180&&code<0x81fc)||(code>0x824f&&code<0x817e))
int isprint(unsigned short sjiscode)
{
for(int i=0;i<6;i++)
{
if(sjiscode>=codesection[i].from&&sjiscode<=codesection[i].to)
return 1;
}
return -1;
}
char UnicodeTostring(unsigned short SjisCode,unsigned char *acs)
{
// a2cd(cda2)->"a2cd"
int i;
acs[0]=(SjisCode>>(8+4));
acs[1]=(SjisCode>>8)&0x000f;
acs[2]=(SjisCode&0x00ff)>>4;
acs[3]=SjisCode&0x000f;
acs[4]=0x00;
for(i=0;i<4;i++)
{
if(acs[i]<=0x09)
acs[i]=acs[i]+0x30;
else
acs[i]=acs[i]-0x0a+0x61;
}
return 0;
}
int main(int argc, char* argv[])
{
unsigned short code,MAXCODE=0xeaa4;
unsigned char codeSigner;
unsigned char lawlessBuf[4],letterBuf[4],sjissingerBuf[4],sjisdoubleBuf[4];
unsigned short lawlessmaxcode=0x7c;
int len;
FILE* pf;
pf=fopen("File.txt","wb");
if(pf==NULL)
return -1;
srand(time(NULL));
for(int i=0;i<100;i++)
{
code=0x22+(rand()%lawlessmaxcode)+1;
if(LAWLESS(code))
{
codeSigner=(unsigned char) code;
fwrite(&code,1,1,pf);
}
code=0x41+(rand()%0x7a)+1;
if(LETTER(code))
{
codeSigner=(unsigned char) code;
fwrite(&code,1,1,pf);
}
code=0xa1+(rand()%0xdf)+1;
if(SJIS_SINGER(code))
{
codeSigner=(unsigned char) code;
fwrite(&code,1,1,pf);
}
code=0x8140+(rand()%0xeaa4)+1;
if(SJIS_SIGN(code))
{
if(isprint(code))
{
fwrite(&code,2,1,pf);
}
else
break;
}
}
fclose(pf);
return 0;
}