本文目录一览:
如何php代码转化为C#代码
public sealed class DESEncryption
{
private static readonly string encryptKey = "YJSERVER";
private static readonly string decryptKey = "YJSERVER";
#region**********Method*******************************
/// summary
/// 加密字符串
/// 注意:密钥必须为8位
/// /summary
/// param name="strText"字符串/param
/// param name="encryptKey"密钥/param
/// return加密后字符串/return
public static string DesEncrypt(string strText)
{
string outString="";
byte[] byKey=null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, encryptKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write) ;
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
outString = Convert.ToBase64String(ms.ToArray());
}
catch(System.Exception)
{
outString = "";
}
return outString;
}
/// summary
/// 解密字符串
/// /summary
/// param name="strText"加了密的字符串/param
/// param name="decryptKey"密钥/param
public static string DesDecrypt(string strText)
{
string outString = "";
byte[] byKey = null;
byte[] IV= {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
byte[] inputByteArray = new Byte[strText.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, decryptKey.Length));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(strText);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
outString = encoding.GetString(ms.ToArray());
}
catch(System.Exception)
{
outString = "";
}
return outString;
}
#endregion
}
}
求哪位大佬把这段php语言转换成c语言,急!十分感谢!
void test() {
int a,b,c,x,x1,x2;
for(a=4;a=2000;a+=2) {
$x = 0;
x1 = 0;
x2 = 0;
for(b=2;ba;b++) {
c = a - b;
if(isPrime(b) isPrime(c)) {
x1 = b;
x2 = c;
x = 1;
break;
}
}
if(x) {
printf("%d=%d+%dbr");
}
}
printf("ok");
}
int isPrime(int n) {
int i;
if (n = 3) {
return n 1;
} else if (n % 2 == 0 || n % 3 == 0) {
return 0;
} else {
for (i = 5; i * i = n; i += 6) {
if (n % i == 0 || n % (i + 2) == 0) {
return 0;
}
}
return 1;
}
}
谁知道PHP如何调用C语言的吗
这是两个完全不一样的程序语言。是不能相互调用的。
但是php的代码(如:循环)有很多是和c语言的代码想通的,只要懂C语言或者是其他的编程语言。那么学习PHP是很容易上手的。
希望对你有帮助。