How to use the rsa key generted by .net with php?

6与win7的兼容问题                                                                     出自何丹的论坛这个问题经常有人问,因为我没有win7,所以也无法测试。我可以确定的是少部分人确实可以在win7上跑VC6,大部人不行。我把一些人的解决方案理出来,欢迎大家补充。 -------- 持啊,我的Windows 7一直支持,从7100到7260都是支 阅读详情

the Solution .infact it's so easy to use rsakey file generated by .net .

------------rsa.class.php-------------------

<?php
/*
*fileName rsa.class.php
*author: laiyunqing<laiyunqing#gmail.com>
 * Some constants
 
*/
define("BCCOMP_LARGER", 1);
class RSA
{
 
/*
  * PHP implementation of the RSA algorithm
  * (C) Copyright 2004 Edsko de Vries, Ireland
  *
  * Licensed under the GNU Public License (GPL)
  *
  * This implementation has been verified against [3]
  * (tested Java/PHP interoperability).
  *
  * References:
  * [1] "Applied Cryptography", Bruce Schneier, John Wiley & Sons, 1996
  * [2] "Prime Number Hide-and-Seek", Brian Raiter, Muppetlabs (online)
  * [3] "The Bouncy Castle Crypto Package", Legion of the Bouncy Castle,
  *      (open source cryptography library for Java, online)
  * [4] "PKCS #1: RSA Encryption Standard", RSA Laboratories Technical Note,
  *      version 1.5, revised November 1, 1993
  
*/

 
/*
  * Functions that are meant to be used by the user of this PHP module.
  *
  * Notes:
  * - $key and $modulus should be numbers in (decimal) string format
  * - $message is expected to be binary data
  * - $keylength should be a multiple of 8, and should be in bits
  * - For rsa_encrypt/rsa_sign, the length of $message should not exceed
  *   ($keylength / 8) - 11 (as mandated by [4]).
  * - rsa_encrypt and rsa_sign will automatically add padding to the message.
  *   For rsa_encrypt, this padding will consist of random values; for rsa_sign,
  *   padding will consist of the appropriate number of 0xFF values (see [4])
  * - rsa_decrypt and rsa_verify will automatically remove message padding.
  * - Blocks for decoding (rsa_decrypt, rsa_verify) should be exactly
  *   ($keylength / 8) bytes long.
  * - rsa_encrypt and rsa_verify expect a public key; rsa_decrypt and rsa_sign
  *   expect a private key.
  
*/

 
/**
  * rsa encrypt data
  *
  * @param binary string $message
  * @param unknown_type $public_key
  * @param numbers $modulus
  * @param numbers $keylength
  * @return binary data
  
*/
 
function rsa_encrypt($message, $public_key, $modulus, $keylength)
 {
  
$padded = RSA::add_PKCS1_padding($message, true, $keylength / 8);
  
$number = RSA::binary_to_number($padded);
  
$encrypted = RSA::pow_mod($number, $public_key, $modulus);
  
$result = RSA::number_to_binary($encrypted, $keylength / 8);

  
return $result;
 }

 
function rsa_decrypt($message, $private_key, $modulus, $keylength)
 {
  
$number = RSA::binary_to_number($message);
  
$decrypted = RSA::pow_mod($number, $private_key, $modulus);
  
$result = RSA::number_to_binary($decrypted, $keylength / 8);

  
return RSA::remove_PKCS1_padding($result, $keylength / 8);
 }

 
function rsa_sign($message, $private_key, $modulus, $keylength)
 {
  
$padded = RSA::add_PKCS1_padding($message, false, $keylength / 8);
  
$number = RSA::binary_to_number($padded);
  
$signed = RSA::pow_mod($number, $private_key, $modulus);
  
$result = RSA::number_to_binary($signed, $keylength / 8);

  
return $result;
 }

 
function rsa_verify($message, $public_key, $modulus, $keylength)
 {
  
return RSA::rsa_decrypt($message, $public_key, $modulus, $keylength);
 }

 
function rsa_kyp_verify($message, $public_key, $modulus, $keylength)
 {
  
$number = RSA::binary_to_number($message);
  
$decrypted = RSA::pow_mod($number, $public_key, $modulus);
  
$result = RSA::number_to_binary($decrypted, $keylength / 8);

  
return RSA::remove_KYP_padding($result, $keylength / 8);
 }


 
/*
  * The actual implementation.
  * Requires BCMath support in PHP (compile with --enable-bcmath)
  
*/

 
//--
 // Calculate (p ^ q) mod r
 //
 // We need some trickery to [2]:
 //   (a) Avoid calculating (p ^ q) before (p ^ q) mod r, because for typical RSA
 //       applications, (p ^ q) is going to be _WAY_ too large.
 //       (I mean, __WAY__ too large - won't fit in your computer's memory.)
 //   (b) Still be reasonably efficient.
 //
 // We assume p, q and r are all positive, and that r is non-zero.
 //
 // Note that the more simple algorithm of multiplying $p by itself $q times, and
 // applying "mod $r" at every step is also valid, but is O($q), whereas this
 // algorithm is O(log $q). Big difference.
 //
 // As far as I can see, the algorithm I use is optimal; there is no redundancy
 // in the calculation of the partial results.
 //--

 function pow_mod($p, $q, $r)
 {
  
// Extract powers of 2 from $q
  $factors = array();
  
$div = $q;
  
$power_of_two = 0;
  
while(bccomp($div, "0") == BCCOMP_LARGER)
  {
   
$rem = bcmod($div, 2);
   
$div = bcdiv($div, 2);

   
if($rem) array_push($factors, $power_of_two);
   
$power_of_two++;
  }

  
// Calculate partial results for each factor, using each partial result as a
  // starting point for the next. This depends of the factors of two being
  // generated in increasing order.

  $partial_results = array();
  
$part_res = $p;
  
$idx = 0;
  
foreach($factors as $factor)
  {
   
while($idx < $factor)
   {
    
$part_res = bcpow($part_res, "2");
    
$part_res = bcmod($part_res, $r);

    
$idx++;
   }

   
array_push($partial_results, $part_res);
  }

  
// Calculate final result
  $result = "1";
  
foreach($partial_results as $part_res)
  {
   
$result = bcmul($result, $part_res);
   
$result = bcmod($result, $r);
  }

  
return $result;
 }

 
//--
 // Function to add padding to a decrypted string
 // We need to know if this is a private or a public key operation [4]
 //--

 function add_PKCS1_padding($data, $isPublicKey, $blocksize)
 {
  
$pad_length = $blocksize - 3 - strlen($data);

  
if($isPublicKey)
  {
   
$block_type = "";

   
$padding = "";
   
for($i = 0; $i < $pad_length; $i++)
   {
    
$rnd = mt_rand(1, 255);
    
$padding .= chr($rnd);
   }
  }
  
else
  {
   
$block_type = "";
   
$padding = str_repeat("ÿ", $pad_length);
  }

  
return "" . $block_type . $padding . "" . $data;
 }

 
//--
 // Remove padding from a decrypted string
 // See [4] for more details.
 //--

 function remove_PKCS1_padding($data, $blocksize)
 {
  
assert(strlen($data) == $blocksize);
  
$data = substr($data, 1);

  
// We cannot deal with block type 0
  if($data{0} == '')
  
die("Block type 0 not implemented.");

  
// Then the block type must be 1 or 2
  assert(($data{0} == "") || ($data{0} == ""));
  
// Remove the padding
  $offset = strpos($data, "", 1);
  
return substr($data, $offset + 1);
 }

 
//--
 // Remove "kyp" padding
 // (Non standard)
 //--

 function remove_KYP_padding($data, $blocksize)
 {
  
assert(strlen($data) == $blocksize);

  
$offset = strpos($data, "");
  
return substr($data, 0, $offset);
 }

 
//--
 // Convert binary data to a decimal number
 //--

 function binary_to_number($data)
 {
  
$base = "256";
  
$radix = "1";
  
$result = "0";

  
for($i = strlen($data) - 1; $i >= 0; $i--)
  {
   
$digit = ord($data{$i});
   
$part_res = bcmul($digit, $radix);
   
$result = bcadd($result, $part_res);
   
$radix = bcmul($radix, $base);
  }

  
return $result;
 }

 
//--
 // Convert a number back into binary form
 //--

 function number_to_binary($number, $blocksize)
 {
  
$base = "256";
  
$result = "";

  
$div = $number;
  
while($div > 0)
  {
   
$mod = bcmod($div, $base);
   
$div = bcdiv($div, $base);

   
$result = chr($mod) . $result;
  }

  
return str_pad($result, $blocksize, "", STR_PAD_LEFT);
 }
}
?>

-------------RSAProcessor.class.php------------------------


<?php
/**
*fileName RSAProcessor.class.php
*author: laiyunqing<laiyunqing#gmail.com>
*/
require_once("rsa.class.php");

class RSAProcessor
{
 
 
private $public_key = null;
 
 
private $private_key = null;
 
 
private $modulus = null;
 
 
private $key_length = "1024";
 
 
 
public function __construct($xmlRsakey=null,$type=null)
 {
         
$xmlObj = null;
 
   
if($xmlRsakey==null)
          {
           
$xmlObj = simplexml_load_file("xmlfile/RSAKey.xml");
          }
          
elseif($type==RSAKeyType::XMLFile)
          {
           
$xmlObj = simplexml_load_file($xmlRsakey);
          }
          
else
          {
           
$xmlObj = simplexml_load_string($xmlRsakey);
          }
         
$this->modulus = RSA::binary_to_number(base64_decode($xmlObj->Modulus));
   
$this->public_key = RSA::binary_to_number(base64_decode($xmlObj->Exponent));
   
$this->key_length = strlen(base64_decode($xmlObj->Modulus))*8;
 }
 
/**
  * get public key
  *
  * @return string public key
  
*/
 
public function getPublicKey()
 {
  
//return base64_encode(RSA::number_to_binary($this->public_key,($this->key_length)/8));
  return $this->public_key;
 }
 
public function getPrivateKey()
 {
  
//return base64_encode(RSA::number_to_binary($this->private_key,($this->key_length)/8));
  return $this->private_key;
 }
 
public function getKeyLength()
 {
  
return $this->key_length;
 }
 
public function getModulus()
 {
  
return $this->modulus;
 }
 
/**
  * encrypt data
  *
  * @param string $data
  * @return base64 encoded  binary string
  
*/
 
public function encrypt($data)
 {
  
return base64_encode(RSA::rsa_encrypt($data,$this->public_key,$this->modulus,$this->key_length));
 }
 
 
public function dencrypt($data)
 {
  
return RSA::rsa_decrypt($data,$this->private_key,$this->modulus,$this->key_length);
 }
 
 
public function sign($data)
 {
  
return RSA::rsa_sign($data,$this->private_key,$this->modulus,$this->key_length);
 }
 
 
public function verify($data)
 {
  
return RSA::rsa_verify($data,$this->public_key,$this->modulus,$this->key_length);
 }
}

class RSAKeyType
{
 
const XMLFile = 0;
 
const XMLString = 1;
}
?>

-------------- encrypt data with public key-----------------

<?php
/**
*fileName testrsa.php
*author: laiyunqing<laiyunqing#gmail.com>
*/
require_once("RSAProcessor.class.php");
$processor = new RSAProcessor

(
"<RSAKeyValue><Modulus>m6ljoeWhmnd0oRnsVEH5iNw3B8+vKVu7v7CVfMyf6bnKEzHa62TRmT/baJiSevoI/vgm2ph/s1JrQQTaGiErHicigwSC

Aw7+i05WFbnz7tOyiiJJVMfsdd+v7Xan9Hiud05FzxoMbM8vpiMHPEIDbGJ1MiXyupTVkz2WcMHyBoJ4S189opktZ43pviUhy0PeuWkyoU7zR54akPmK

Yg+z5Zr1r7K8lUZ1a3TThfJGxTQR/uZMtZz/q8QF0AANVQ/eyahTv9icBzBoDuncS0Y5l3vqogW1C/ltJvhJpvSn/OgjbRjuixCAptOUmRd13sDWU95/

x0bMq+Lg68lj2OjJ1Q==</Modulus><Exponent>AQAB</Exponent><P>zfvdBsMLlmo+4PAUYLgSV2xyyVa7ZqFjkJaAE4EbYuH24EoZjrzeiJR++D

FUT/GUhjfZ5eZ/5e29dXwk0sKUw6nHzBdBtOPp5fr4t5SKLEcWY+J+zLUSOlhG9NUkohFf6+Miy2Y7BLpXVrcl6UwXV0ak8KkTPB2l/aIMwYj5dgc=</

P><Q>wXV0sA3nDzoSDQA/4QSu/WIlBhkA3jZ7K7G9Z9rpP1A0vH+bZeyCIyo52u8ahGuYbubaizF1XMp+Xv3Mh2KmRbt7+UptwEwbFAUiiad2a312mqm

j7IJd7gRjGkyzKEm+6fpNeY3NFLNVNhccBqzhNkRoM22xnvQcImD10XVAakM=</Q><DP>wd1HdCLEWCfc0DYE59a2pINUMXyo2foRTDbpifHcRZ+ojAY

Rsc6+nsssCQnccXVMNVqBgSgEvfGYe+eAfMBX5SN5APPuioJrVGF2DsoFlZC+WPoGH0JYSoNlHO8yEDrMDaXzzH2GFHgQ1XOAged0nFbHzB1FFjJNVL5

cxRXWu6c=</DP><DQ>QDKuCk5SwubOXqoaiJ15RHRxPNjHRPZnYVSWOgSXKn9/QJ5H/0bA2NKGaHS4JAFgkEzjcRV0kNpRnUwztymxa6qPtWZRjWK0Ca

y6jVuZHIqB9UkeMLoCWZ3zFSMmwNPYGuUJGLFJwPjR6iU5E64C/nMs8QQR0WHIhFAQwvVZ7uk=</DQ><InverseQ>JckMSlJR10VZdnp83VPjrZ/Z+63

CGu3tWHm7f4DJ8IwjJWr8FlCpbSwiP6a4e9Upv6bUn/tOj2gY6MMq5G5yTKm2SCRvpUKRu4NCmWAt7vlFv0Z6pkXlTOpzvVjv3v16+dIZOA5Zn+v7+r1

xbdYdH20KRAbiBO3MfQP7s+VJJvM=</InverseQ><D>W1xrBr2hQOj1wgxWAgoK7IHbprEFrK+TnWmGA46SGPsbmHJ9fAVbY6fwHg7Wgmk4WHXLUCeLY

/Nu0eWIISfwh60Oe3ls2WC2k4qxyeSvQDBuLNb81U7WAUT9m9E1uK4QMCP3oxs1ybM80zTh7UMNgVK0WG+fbFUomVffcWTTqW+Fu12PEIO+UR/85oq+x

qVlTzYAEzt1OE9IhkYiRzi99ePXeH2gFltzJ/fb/7jLsDTkhM2eiYTGyOTZmBnen6c6a8b9LFTY4Bc0bGpk5ezHkub6F8p2ZgL/JgIOJMyRZICjDjs+9

k9PTmMTFsCF6xzHY15Fg25xIDYzIyx1rrRUjQ==</D></RSAKeyValue>
",RSAKeyType::XMLString);
$rs =  $processor->encrypt("Hello,It's Works.");
echo $rs;
?>

 

StarUML最新版汉化与破解二合一教程:5分钟搞定永久使用 本文提供StarUML最新版的高效使用指南,涵盖从安装到深度定制的全流程优化方案。包括软件获取最佳实践、界面个性化设置、核心建模技巧、团队协作策略及性能优化建议,帮助架构师和开发团队提升UML建模效率。特别推荐版本控制集成和文档自动化输出方案,适用于各类规模的项目开发。 阅读详情

相关推荐

【保姆级教程】不到一元32位芯片 DIY迷你时钟

基于不到一元的CH32V003F4P9芯片制作的迷你多功能时钟。

twen51的博客 1820

C#开发的SharpDict在线词典

C#开发的SharpDict在线词典支持中英文查询,源码还需完善,先放两个图片先.     图一、 英文查询     图二、中文查询下载本程序(右键下载,并把扩展名改为rar)下载修正版本2008-4-2日更新(支持插件式开发)                                                           图三:同时支持

iLinux 4409

【maxENT】从数据到地图:R语言实现最大熵物种分布建模全流程解析

本文详细解析了如何使用R语言实现最大熵模型(MaxEnt)进行物种分布建模的全流程。从数据准备、环境变量处理到模型训练与参数调优,再到模型评估与结果可视化,提供了实用的代码示例和避坑指南。特别适合生态学研究者利用最大熵模型处理物种分布数据,提升研究效率。

weixin_27244795的博客 223

在Apache中配置ASP.NET支持

      本文简单介绍了在 WINDOWS 2000 SERVER + .NET FrameWork 1.1下APACHE2.058 成功配置ASP.NET支持的一个过程。    本文前提是成功安装好了FrameWork 1.1 并在 IIS下asp.net程序运行良好。    一、下载所需软件         1. apache 2.0.58 (可以到http://www.skyc

iLinux 4360

定位教程7---旋转中心标定之方法二

手算相机相对机器人关系

Quintin 6237

YOLOv8融合HAttention:激活更多像素的注意力机制科研实践指南

HAttention通过层级化像素激活与融合的设计,为YOLOv8的像素级特征利用能力带来了质的飞跃。从原理理解到代码实现,再到集成调优,每一步都是科研中“解决像素信息遗漏难题”的具体实践。如果你在实验中发现某类细节或大尺度目标的检测仍有不足,可以尝试结合数据增强(如随机裁剪、多尺度训练)来强化模型对像素特征的学习能力。科研的价值在于不断挖掘技术的潜力,希望这份指南能真正帮你在目标检测的像素级特征利用领域找到新的突破点,祝你在科研探索中持续收获创新与成长。

FJN110的博客 111

C#开发的whois查询客户端(原创)

 C#开发的whois查询客户端,对喜欢抢注域名的朋友有一定的帮助。WINFORM版本效果图如下                                    图一、SharpWhois WinForm 版本                               图二、whois命令行版本现在要查询域名的话就不用打开一些无聊的网站了。软件下载:点击下载(扩

iLinux 3838

YOLOv11改进 | 检测头篇 | 利用AFPN辅助YOLOv11检测头进行特征融合识别(全网独家创新)

本文给大家带来的最新改进机制是利用AFPN(渐近特征金字塔网络)来优化检测头,AFPN的核心思想是通过引入一种渐近的特征融合策略,将底层、高层和顶层的特征逐渐整合到目标检测过程中。这种渐近融合方式有助于减小不同层次特征之间的语义差距,提高特征融合效果,使得检测模型能更好地适应不同层次的语义信息。本文在AFPN的结构基础上,为了适配YOLOv11改进AFPN结构,同时将AFPN融合到YOLOv11中(因为AFPN需要四个检测头,我们只有三个,下一篇文章我会出YOLOv11适配AFPN增加小目标检测头)

Snu77的博客 3753

CLI, CIL&CLR

CLI(Common Language Infrastructure)是由微软公司制定的一个开放标准或规范(open specification),并有ECMA-335和ISO/IEC 23271两个版本。它描述了一个通用的系统架构(artechiture),使得任何使用这个架构的高级语言如C#和Managed C++等能够在不重写任何代码的情况下运行于任何计算机架构和平台(platfor

iLinux 3454

C++实现设计ATM机系统

这个示例实现了一个基本的ATM机系统,支持注册、登录、存款、取款、查询余额和保存数据等功能。当然,这只是一个简单的ATM机模拟,实际的ATM机系统需要更复杂的逻辑和更严格的安全措施。C++编写一个简单的ATM机系统,我将提供一个基本的实现示例,但由于ATM机系统的复杂性和安全性要求,这只是一个简单的模拟,不适合在实际环境中使用。试设计一简单模拟ATM机系统,系统以菜单方式工作,采用自定义函数设计各功能模块被主菜单调用,使之能提供以下基本选项。=========欢迎使用ATM=========

走向CTO的路上... 1250

高通平台N4单路输入的720P相机预览

N4的一路720P Camera作为MIPI摄像头使用

llw21680的专栏 167

C#中结合使用SQLDMO实现备份、还原SQLserver数据库

//---DBTools.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Magicbit.Fram

iLinux 3136

Flow Match 原理 及应用

Flow Matching(流匹配)是生成模型的范式革命——用确定性ODE替代随机扩散过程,在自动驾驶轨迹预测中实现10倍采样加速和更高生成质量。更快的采样速度:通常只需 10-50 步就能生成高质量样本更稳定的训练:避免了传统扩散模型中复杂的噪声调度理论基础:基于连续正规化流(Continuous Normalizing Flows)核心思想:Flow Matching 通过学习一个 向量场(vector field) 来直接建模从噪声分布到目标分布的连续变换路径。

@bangbang的博客 129

Visual Studio 2005 使用技巧一则

        最近系统在我安装了N多软件又卸载了N多软件后老是出现莫明其妙的错误,懒得手动去修复,尝试下载了超级兔子清理/修复了下。旧的问题解决后却发现新的问题也来啦,VS2005就没有办法新建项目了!系统提示,没有可用的模版,还好另一个提示蛮有用的,提示查看事件日志 。那就查看下吧,        进入 控制面板->管理工具->事件查看器 后,可以找到如下所示(图一)的错误提示  

iLinux 2807

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

简单操作让你的.NET托管程序启动更快、体积更小

         很多搞.NET开发的可能也跟都有这个习惯,在编写.NET托管程序的时候,喜欢用到以前的一些类库,或是第三方提供的类库,由于没有采用源码方式来编译(没有编译到同一程序集中).这样一来,编译好的应用程序就可能是N个散列的文件。更有一点需要注意的是,用户可以非常简单的就看出,你用到了哪些第三方的类库...我想这应该都不是大家很喜欢看到的吧,其实,利用.NETZ这个开源的免费小工具,就可

iLinux 2287

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

stardict字典文件格式识别类

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;namespace cn.Laiyunqing{   public class nStarDict    {       private string idxFile;       private s

iLinux 2123

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

一个简单的OleDb数据操作辅助类

using System;using System.Data;using System.Data.OleDb;using System.Collections;namespace Laiyunqing.OleDbHelper...{    数据库连接对象#region 数据库连接对象    /**////     /// 通过调用DataConnection;获得数据库连接字符串;    //

iLinux 1750

解决Visual Studio 2008来生VisualBasic 项目的性能问题

最近在用VB.NET生成一个WEB项目时,发现基本没办法调试,只要一debug,Visual Studio 2008就停止相应,再经过漫长的等待后(30分钟左右)后,才进入调试状态。这个问题,搞得我够郁闷的了,也困扰N久,最才在MS知识库的这篇文章的帮助下得以解脱——原来都是MS的错,我还以为是我的机器出故障了,汗。。。FIX: You may experience performance i

iLinux 1710

FlowDocument in WPF

下图演示最常与流内容一起使用的对象:Block 派生类:ParagraphParagraph 通常用于将内容分组到一个段落中。Paragraph 的最简单且最常见的用途是创建文本段落。SectionSection 只用于包含其他 Block 派生元素。它不会向其中包含的元素应用任何默认格式。不过,在 Section 上设置的任何属性值都适用于其子元素。使用节能

iLinux 1664

在vs.net 中使用用户控件...

刚看到有网友问,怎么在VS.NET环境中“可视化”的使用用户控件,其实,也是非常简单的一件事,具体操作为:直接从VS.NET的解决方案资源管理器中把文件拖放到所需该控件的页面上就可以了图一.使用VS.NET可视化操作用户控件 

iLinux 1505

ASP.NET之ORACLECLINE操作辅助类(C#版)

使用于DOTNET FRAMEWORK 1.1//-----文件名:OracleHelper.cs------using System; using System.Configuration; using System.Data; using System.Data.OracleClient; using System.Collections; namespace com.DBUtilit

iLinux 1388

图解WINDOWS 2000设置虚拟主机

       经常看到UNIX/LINUX环境下APACHE虚拟主机的设置教程、可好像很少看到WIN环境下IIS设置虚拟主机的方法,本文即以WINDOWS 2000下的IIS 5.0为例。以图形化的方式介绍了WINDOWS 2000 server环境下,虚拟主机的设置。(windows2003,NT设置方法跟此大体相同,XP专业版本、2K专业版本不支持设置多个虚拟主机。)STEP 1.右击【我

iLinux 1323

.netframework下Span<char>转数值

【代码】.netframework下Span<char>转数值。

henreash的专栏 187

EasyAdminBlazor 2.7.0 新功能全览:AI 助手、数据多语言、混合多租户与 .NET 11

EasyAdminBlazor.AI 源码集成,实现后台AI工具链:模型管理、调用记录、权限校验(HasPath)与操作日志统一。支持OpenAI兼容接口,按场景设默认模型,额度由宿主通过IAiAccessGuard控制。多语言功能基于URL前缀,业务数据自动译文,CMS无缝适配。混合多租户支持独立库与共享库,套餐绑定菜单自动下发。内置批量筛选、私有上传、类型化配置、短信验证码、访问闸门等实用能力。.NET 11新增电路自动暂停与优雅停机。升级需注意五项破坏性变更,详见文档。

gudufy的博客 341

技术速递|宣布推出 .NET 11

今天,我们很高兴地宣布正式发布 .NET 11!此次年度版本让现代应用的构建更快速、更高效,并带来了对 C# 15、ASP.NET Core、.NET MAUI 和 Windows 开发的多项改进。借助数百项运行时优化、更灵敏的 SDK 工具以及更低的日常命令开销,你可以减少等待时间,把更多精力投入到创造之中。你可以借助更丰富的 C# 语言特性、AI 编程工具和智能体能力,构建更出色的 Web 应用和跨平台应用。

MicrosoftReactor的博客 375

把 Mission Planner 搬上鸿蒙 PC:把 .NET 内核烧成 so,移植鸿蒙应用

将 Mission Planner 移植至鸿蒙 PC,采用 .NET NativeAOT 编译内核为无 JIT 的 libmagcs.so,通过 C ABI 与 NAPI 桥接,实现纯原生运行。以 ArkUI 重写外壳,保留核心协议与状态逻辑,支持 MAVLink 心跳、参数/任务传输及多链路通信。项目完成度高,仅地图瓦片与固件烧写待完善,验证了“内核原样迁移 + 外壳重构”的 T1 级适配路径,为开源鸿蒙生态注入关键飞行控制能力。

轻口味的专栏 5327
上一篇: 使用HttpHandler功能,把aspx文件编译进dll
下一篇: 让Totem使用Xine-lib库
forlinux
博客等级 码龄21年 53粉丝 95原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址