对一系列java8函数式编程或计算进行编程时,以下哪种方式可获得最佳性能

 上传我的文档
 下载
 收藏
该文档贡献者很忙,什么也没留下。
 下载此文档
CLAD考试题目
下载积分:300
内容提示:CLAD考试题目
文档格式:PDF|
浏览次数:55|
上传日期: 08:48:15|
文档星级:
全文阅读已结束,如果下载本文需要使用
 300 积分
下载此文档
该用户还上传了这些文档
CLAD考试题目
官方公共微信查看: 8159|回复: 7|关注: 0
这是一个hash函数在matlab中的编程,希望对大家有用
<h1 style="color:# 麦片财富积分
新手, 积分 5, 距离下一级还需 45 积分
关注者: 1
function h = hash(inp,meth)
% HASH - Convert an input variable into a message digest using any of
%& && &&&several common hash algorithms
% USAGE: h = hash(inp,'meth')
% inp&&= input variable, of any of the following classes:
%& && &&&char, uint8, logical, double, single, int8, uint8,
%& && &&&int16, uint16, int32, uint32, int64, uint64
% h& & = hash digest output, in hexadecimal notation
% meth = hash algorithm, which is one of the following:
%& && &&&MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512&&
% NOTES: (1) If the input is a string or uint8 variable, it is hashed
%& && && && &as usual for a byte stream. Other classes are converted into
%& && && && &their byte-stream values. In other words, the hash of the
%& && && && &following will be identical:
%& && && && && && && &'abc'
%& && && && && && && &uint8('abc')
%& && && && && && && &char([97 98 99])
%& && && && &The hash of the follwing will be different from the above,
%& && && && &because class &double& uses eight byte elements:
%& && && && && && && &double('abc')
%& && && && && && && &[97 98 99]
%& && && && &You can avoid this issue by making sure that your inputs
%& && && && &are strings or uint8 arrays.
%& && &&&(2) The name of the hash algorithm may be specified in lowercase
%& && && && &and/or without the hyphen, if desired. For example,
%& && && && &h=hash('my text to hash','sha256');
%& && &&&(3) Carefully tested, but no warranty. Use at your own risk.
%& && &&&(4) Michael Kleder, Nov 2005
% EXAMPLE:
% algs={'MD2','MD5','SHA-1','SHA-256','SHA-384','SHA-512'};
% for n=1:6
%& &&&h=hash('my sample text',algs{n});
%& &&&disp([algs{n} ' (' num2str(length(h)*4) ' bits):'])
%& &&&disp(h)
inp=inp(:);
% convert strings and logicals into uint8 format
if ischar(inp) || islogical(inp)
& & inp=uint8(inp);
else % convert everything else into uint8 format without loss of data
& & inp=typecast(inp,'uint8');
% verify hash method, with some syntactical forgiveness:
meth=upper(meth);
switch meth
& & case 'SHA1'
& && &&&meth='SHA-1';
& & case 'SHA256'
& && &&&meth='SHA-256';
& & case 'SHA384'
& && &&&meth='SHA-384';
& & case 'SHA512'
& && &&&meth='SHA-512';
& & otherwise
algs={'MD2','MD5','SHA-1','SHA-256','SHA-384','SHA-512'};
if isempty(strmatch(meth,algs,'exact'))
& & error(['Hash algorithm must be ' ...
& && &&&'MD2, MD5, SHA-1, SHA-256, SHA-384, or SHA-512']);
% create hash
x=java.security.MessageDigest.getInstance(meth);
x.update(inp);
h=typecast(x.digest,'uint8');
h=dec2hex(h)';
if(size(h,1))==1 % remote possibility: all hash bytes&&128, so pad:
& & h=[repmat('0',[1 size(h,2)]);h];
h=lower(h(:)');
这个里面有点小错误,还希望高手能给予一点帮助,改正过来.
<h1 style="color:# 麦片财富积分
非常感谢。没发现错误啊。
<h1 style="color:# 麦片财富积分
本帖最后由 phenry 于
16:16 编辑
你的程序运行起来没有错误!
看了你的程序后,我才明白原来matlab支持java接口,谢谢!
<h1 style="color:# 麦片财富积分
我要编写一个hash函数,目的是为了让三个输入参数经过哈希函数后,得到一个唯一的hash输出,比如三个输入分别是320位,161位,64位的二进制值,而输出是31位的二进制值
谁能帮我,。。。。谢谢呀
<h1 style="color:# 麦片财富积分
你换一个高版本的matlab
<h1 style="color:# 麦片财富积分
网络公主 发表于
我要编写一个hash函数,目的是为了让三个输入参数经过哈希函数后,得到一个唯一的hash输出,比如三个输入分 ...
你把楼主的hash函数改为31位输出,其实用这个128位的也可以。三个输入分别带能用这个功能函数,三个输出值进行按位异或计算就可以用了
<h1 style="color:# 麦片财富积分
<h1 style="color:# 麦片财富积分
请问各位大神,我要怎么样得到函数里各个节点的128位输出呢?万分感谢
站长推荐 /2
利用MATLAB进行传感器数据分析
MATLAB中文论坛是全球最大的 MATLAB & Simulink 中文社区。用户免费注册会员后,即可下载代码,讨论问题,请教资深用户及结识书籍作者。立即注册加入我们吧!
MATLAB官方社交平台
MATLAB中文论坛微社区excel中if函数的返回值是一算式,并且要这个算式进行计算,怎么编写这个程序?_学习帮助 - QQ志乐园
您的当前位置: &
excel中if函数的返回值是一算式,并且要这个算式进行计算,怎么编写这个程序?
来源: |人气:669 ℃|时间: 00:58:43
为了解决用户可能碰到关于"excel中if函数的返回值是一算式,并且要这个算式进行计算,怎么编写这个程序?"相关的问题,志乐园经过收集整理为用户提供相关的解决办法,请注意,解决办法仅供参考,不代表本网同意其意见,如有任何问题请与本网联系。"excel中if函数的返回值是一算式,并且要这个算式进行计算,怎么编写这个程序?"相关的详细问题如下:
如果A1&0,则返回 A1+100,否则返回 A1-100=IF(A1&0,A1+100,A1-100)网友回答
||||点击排行c++程序设计第3版谭浩强课后答案
当前位置: >>
13:49:11&&分类: c++程序设计第三版谭浩强课后答案&&参与: 人
C++编程:编写一个函数days,实现上面的计算。由主函数将年月日传递给days,计算出该日在本年中是第几天并将结果传回主函数输出。
&以下是此题的【c++源代码】,
#include &iostream&
struct y_m_d
&int main()
& int days(int,int,int);&&&&&&&&&&&&&&&&&&&& /* 对days函数的声明 */
& int day_
& cout&&"input year,month,day:";
& cin&&date.year&&date.month&&date.
& day_sum=days(date.year,date.month,date.day);
& cout&&date.month&&"/"&&date.day&&" is the "&&day_sum
&& &&"th day in "&&date.year&&
& return 0;
int days(int year,int month,int day)&&&&&&& /* 定义days函数 */
{int day_sum,i;
&int day_tab[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
&day_sum=0;
&for (i=1;i&i++)
&& day_sum+=day_tab[i];
&day_sum+=
&if ((year%4==0 && year%100!=0 || year%4==0) && month&=3)
&&&& day_sum+=1;
&return(day_sum);
本文链接:
本站文章搜索:
相关文章 18:14:26 15:22:52 15:14:37 15:10:17 15:1:31 15:0:26

我要回帖

更多关于 python 函数式编程 的文章

 

随机推荐