fcs

来源:互联网 发布:手机淘宝打不开咋办 编辑:程序博客网 时间:2024/05/17 01:58

// fcs.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
//#include "WinDef.h"

//#include <string>  
#include   <windows.h>  
//#include <string.h>
#include <stdlib.h>
//#include <string>
//#include <cstring> // mfc的类
//#include <string> 
 #include <stdio.h>  
    #include <string>  
    #include <iostream> 
using   namespace   std; 


void MyFunc(char senddata[300] , int i)//()//(char senddata[300] , int i)
{
 i=(int)strlen(senddata);
 int j ;
 int i16;
 BYTE STR[300] ;
  BYTE sum = 0x00 ,c1 = 0x0f ,c2 = 0xf0 ;

  for (j=0;j<i;j++)
   STR[j]=senddata[j];

 // string strmy1="123ed56c";
  //std::string
  string strmy1=senddata;//"123ed56c";
  string strmy="";
 for (j=0;j<i;j=j+2)
 {
  
    strmy=strmy1.substr(j,2);
  //strmy=
  i16=strtol((char *)strmy.c_str(), NULL, 16);
  sum^=i16;
 }
   // sum^=STR[j]; // strtol((char *)strmy.c_str(), NULL, 16)

 c1 = c1&sum;
 c2 = c2&sum;
 c2 = c2 >> 4 ;

  
 if(c2<=9)
  STR[j]=c2+48;
 else
  STR[j]=c2+55;

 if(c1<=9)
  STR[j+1]=c1+48;
 else
  STR[j+1]=c1+55;

 

 i=j+2;

  for (j=0;j<=i;j++)
  senddata[j]=(char)STR[j];

  
}


int main(int argc, _TCHAR* argv[])
{
  
 char senddata[300]="5500";//"cd"; --> cd07  // “@00WD00000028  //  59  c --> 0x63  ,d  --> 0x64
 MyFunc(  senddata  , 4);
 std::cout<<endl<<senddata;
 getchar();
 return 0;
}

   

原创粉丝点击