<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cyher.NET &#187; mac</title>
	<atom:link href="http://cyher.net/tag/mac/feed" rel="self" type="application/rss+xml" />
	<link>http://cyher.net</link>
	<description>Technology, Life, Code, OpenSource, *nix, Mac and iphone, Mobile development</description>
	<lastBuildDate>Wed, 16 Mar 2011 01:25:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>伪造?还是检测信用卡 cocoa, Objc实现</title>
		<link>http://cyher.net/apple/cocoa/credit-card-check</link>
		<comments>http://cyher.net/apple/cocoa/credit-card-check#comments</comments>
		<pubDate>Tue, 15 Mar 2011 15:33:38 +0000</pubDate>
		<dc:creator>cyher</dc:creator>
				<category><![CDATA[cocoa]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[算法]]></category>

		<guid isPermaLink="false">http://cyher.net/?p=637084</guid>
		<description><![CDATA[伪造? 还是去检测一张信用卡? 看完这个图, 相信很容易了解其中的数学算法. 原始链接:http://www.geekv5.com/archives/2859 英文原始链接:http://www.mint.com/blog/trends/credit-card-code-01202011/ 好了其实这个小知识还是很有趣的, 作为向geek前进的我们, 怎么能不知道这样的小trick. 看见这个，会想起什么？我们的思维真的会从伪造信用卡这个keywrod延伸到，卡片的生产，怎么把磁条信息录入，怎么去设这个陷阱让人踩了还不知道？ 至少我不是的。。我第一个想到的是如果我有一个iphone，我的iphone上有一个软件通过摄像头，对着一张信用卡来信用卡真伪识别。So cool? 其实这样的思维常常出现在每个人的脑海中，那些so cool的创意程序可能就在这瞬间的头脑风暴产生了。好吧，其实本不应该说这么多的。其实我是想鼓励自己，纸上得来终觉浅，绝知此事要躬行，just do it. 其实这个信用卡真伪的识别是基于，一个叫做Luhn 的算法 详细内容请移步 http://en.wikipedia.org/wiki/Luhn_algorithm 我对这个算法的描述就是: 从右倒左, 偶数位 * 2, 如果偶数大于10, 则个位+(十位/10) 把奇数位和刚刚得出的偶数位相加得出 sum sum如果能够mod 10 = 0 那就是正确的 这里给出C的code, wikipedia里面有java和pyhon的 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [...]]]></description>
			<content:encoded><![CDATA[<p>伪造? 还是去检测一张信用卡? 看完这个图, 相信很容易了解其中的数学算法.</p>
<p>原始链接:<a href="http://www.geekv5.com/archives/2859">http://www.geekv5.com/archives/2859</a></p>
<p>英文原始链接:<a href="http://www.mint.com/blog/trends/credit-card-code-01202011/">http://www.mint.com/blog/trends/credit-card-code-01202011/</a></p>
<p><a href="http://cyher.net/wp-content/uploads/2011/03/cc.jpg" rel="lightbox[637084]"><img class="aligncenter size-full wp-image-637085" title="How to Validate a Credit Card" src="http://cyher.net/wp-content/uploads/2011/03/cc.jpg" alt="" width="440" height="1206" /></a>好了其实这个小知识还是很有趣的, 作为向geek前进的我们, 怎么能不知道这样的小trick.</p>
<p>看见这个，会想起什么？我们的思维真的会从伪造信用卡这个keywrod延伸到，卡片的生产，怎么把磁条信息录入，怎么去设这个陷阱让人踩了还不知道？</p>
<p>至少我不是的。。我第一个想到的是如果我有一个iphone，我的iphone上有一个软件通过摄像头，对着一张信用卡来信用卡真伪识别。So cool? 其实这样的思维常常出现在每个人的脑海中，那些so cool的创意程序可能就在这瞬间的头脑风暴产生了。好吧，其实本不应该说这么多的。其实我是想鼓励自己，纸上得来终觉浅，绝知此事要躬行，just do it.</p>
<p>其实这个信用卡真伪的识别是基于，一个叫做Luhn 的算法 详细内容请移步<a href=" http://en.wikipedia.org/wiki/Luhn_algorithm"> http://en.wikipedia.org/wiki/Luhn_algorithm</a></p>
<p>我对这个算法的描述就是:</p>
<ul>
<li>从右倒左, 偶数位 * 2, 如果偶数大于10, 则个位+(十位/10)</li>
<li> 把奇数位和刚刚得出的偶数位相加得出 sum</li>
<li>sum如果能够mod 10 = 0 那就是正确的</li>
</ul>
<p>这里给出C的<a href="http://www.mathematik.uni-bielefeld.de/~sillke/codes/luhn-method">code</a>, wikipedia里面有java和pyhon的</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code"><pre class="c" style="font-family:monospace;">The Luhn Mod<span style="color: #339933;">-</span><span style="color: #0000dd;">10</span> Method <span style="color: #009900;">&#40;</span>ISO <span style="color: #0000dd;">2894</span><span style="color: #339933;">/</span>ANSI <span style="color:#800080;">4.13</span><span style="color: #009900;">&#41;</span> involves a check digit in the
one<span style="color: #ff0000;">'s position.  The check digit is calculated starting at the right with
the digit immediately preceding the check digit (ten'</span>s digit<span style="color: #009900;">&#41;</span> and moving
toward the left<span style="color: #339933;">,</span> doubling every other digit.  <span style="color: #202020;">If</span> a doubled digit is greater
than nine<span style="color: #339933;">,</span> the two digits are added to together to obtain a single<span style="color: #339933;">-</span>digit
result.  <span style="color: #202020;">The</span> sum of all the resulting digits <span style="color: #009900;">&#40;</span>including those skipped<span style="color: #009900;">&#41;</span> is then
taken modulo with <span style="color: #0000dd;">10</span><span style="color: #339933;">,</span> to obtain the check digit.
&nbsp;
<span style="color: #202020;">Below</span><span style="color: #339933;">,</span> is untested code.
&nbsp;
<span style="color: #808080; font-style: italic;">/************************************************************************
*  LuhnMod10 - self-checking scheme for validating card account numbers
*  according to ISO 2894/ANSI 4.13.
*
*    Ex:  cardNumber = &quot;795102879015546&quot;
*         strlen(cardNumber) == 15
*         LuhnMod10(cardNumber, 14) == 6 == cardNumber[14]
*
************************************************************************/</span>
<span style="color: #993333;">int</span> LuhnMod10<span style="color: #009900;">&#40;</span><span style="color: #993333;">char</span><span style="color: #339933;">*</span> cardNumber<span style="color: #339933;">,</span> <span style="color: #993333;">int</span> size<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #993333;">static</span> <span style="color: #993333;">int</span> table<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000dd;">10</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #339933;">,</span><span style="color: #0000dd;">5</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span><span style="color: #339933;">,</span><span style="color: #0000dd;">8</span><span style="color: #339933;">,</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span><span style="color: #0000dd;">2</span><span style="color: #339933;">,</span><span style="color: #0000dd;">4</span><span style="color: #339933;">,</span><span style="color: #0000dd;">6</span><span style="color: #339933;">,</span><span style="color: #0000dd;">8</span><span style="color: #339933;">,</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span><span style="color: #0000dd;">3</span><span style="color: #339933;">,</span><span style="color: #0000dd;">5</span><span style="color: #339933;">,</span><span style="color: #0000dd;">7</span><span style="color: #339933;">,</span><span style="color: #0000dd;">9</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> i<span style="color: #339933;">=</span>size<span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #339933;">,</span> odd<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">,</span> sum<span style="color: #339933;">=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;=</span><span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">--</span><span style="color: #009900;">&#41;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>isdigit<span style="color: #009900;">&#40;</span>cardNumber<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
      sum <span style="color: #339933;">+=</span> table<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#40;</span>odd<span style="color: #339933;">=</span><span style="color: #0000dd;">1</span><span style="color: #339933;">-</span>odd<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>cardNumber<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">-</span><span style="color: #ff0000;">'0'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  sum <span style="color: #339933;">%=</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span>sum <span style="color: #339933;">?</span> <span style="color: #0000dd;">10</span><span style="color: #339933;">-</span>sum <span style="color: #339933;">:</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>               <span style="color: #808080; font-style: italic;">/* return the check digit */</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>站在巨人的肩膀是不是有一种很强大的感觉。好吧，我们既然要把要在iphone上实现，那首先需要一个Objective-C的代码. here is it ,从C代码修改过来并不是很难。</p>
<p>CheckCreditCard.h</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="objective-c" style="font-family:monospace;">#import 
&nbsp;
@interface CheckCreditCard : NSObject {
	IBOutlet NSTextField *ccNum;
	IBOutlet NSTextField *ccTrue;
&nbsp;
}
- (IBAction)checkIt:(id)sender;
@end</pre></td></tr></table></div>

<p>CheckCreditCard.m</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="objective-c" style="font-family:monospace;">//  CheckCreditCard.m
//  Verify Credit Card
//
//  Created by cyher on 11-3-8.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
&nbsp;
#import &quot;CheckCreditCard.h&quot;
&nbsp;
@implementation CheckCreditCard
&nbsp;
- (id)init
{
	[super init];
	NSLog(@&quot;Init!&quot;);
	return self;
}
&nbsp;
- (IBAction)checkIt:(id)sender
{
	int sumTable[10][10] = {{0,1,2,3,4,5,6,7,8,9},{0,2,4,6,8,1,3,5,7,9}};
	int sum = 0, flip = 0;
&nbsp;
	NSString *string = [ccNum stringValue];
	NSLog(@&quot;ccNum = %@&quot;, string);
	if ([string length] == 0)
		return;
	for (int i = [string length] - 1; i &amp;gt;= 0; i--)
		sum +=
		sumTable[flip++ &amp;amp; 0x1][[string characterAtIndex:i] - '0'];
	NSLog(@&quot;sum = %d&quot;, sum);
	if (0 == (sum % 10)) {
		[ccTrue setStringValue:[NSString stringWithFormat
				       :@&quot;This is a real Credit Card!&quot;,
				       [string length]]];
	} else {
		[ccTrue setStringValue:[NSString stringWithFormat
					:@&quot;This is fake Credit Card!&quot;,
					[string length]]];
	}
&nbsp;
	return;
}
&nbsp;
@end</pre></td></tr></table></div>

<p>来我们看看在mac上的效果吧:</p>
<p><a href="http://cyher.net/wp-content/uploads/2011/03/fake.png" rel="lightbox[637084]"><img class="aligncenter size-full wp-image-637087" title="fake" src="http://cyher.net/wp-content/uploads/2011/03/fake.png" alt="" width="280" height="135" /></a></p>
<p>&nbsp;</p>
<p><a href="http://cyher.net/wp-content/uploads/2011/03/real.png" rel="lightbox[637084]"><img class="aligncenter size-full wp-image-637088" title="real" src="http://cyher.net/wp-content/uploads/2011/03/real.png" alt="" width="285" height="137" /></a></p>
<p>怎么样很简单吧， 如果我们能够调用goggle（google的图形识别程序，基于云计算）的API，我们能够从图片转换成数字。其实一个有意思的小软件就成了. 希望我们能运用生活中的小科技, 来改变我们的生活吧.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://cyher.net/apple/cocoa/credit-card-check/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>原来苹果不会那么傻阿</title>
		<link>http://cyher.net/apple/apple_is_not_stupid</link>
		<comments>http://cyher.net/apple/apple_is_not_stupid#comments</comments>
		<pubDate>Thu, 10 Sep 2009 02:31:24 +0000</pubDate>
		<dc:creator>cyher</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[nano]]></category>
		<category><![CDATA[shuffle]]></category>
		<category><![CDATA[touch]]></category>

		<guid isPermaLink="false">http://cyher.net/?p=636996</guid>
		<description><![CDATA[话说apple 09.09.09的发布会 Rock n&#8217; Roll,看来苹果选的日子也不错阿, 殊不知地球这边就一个北京就有近20000对情侣喜结连理. 发布会之前, 我又一个想法, 当3代touch配上3GS的处理器和内存, 还有摄像头和mic, 我就入个touch+any andorid手机来代替我的iphone. 哈哈, 可惜apple不会这么傻, 最起码没我这么梦幻. 这不是技术问题吧? Maybe,之前听说了touch有技术问题没有解决. 但我觉得, 这就是apple的经营理念, apple不傻, 真的出了个那么牛逼的touch, 除了打电话什么都和iphone一样了而价格又第很多, 人们确实都会像我一样 touch+any phone = iphone的. apple就是想告诉我们,我们的产品是没有完美的, 如果想完美,那价格也一定不是完美的, touch+phone ≠ iphone 3GS. 或许, touch+nano+phone = iphone 3GS,但是价格也是划等号的, 为什么我们不选又小又cool 的 iphone 3GS. 经过上面的分析, apple其实不会那么傻的, 他每次做产品, 定价和功能总能对应, 并且让你难以选择, 功能没有强大多少,但是你需要, 价格提高的幅度也让你难以抉择. 哈哈,到现在你就中了apple的心里陷阱了, 现在你明白了, 为什么果粉,总是有很多apple的设备, 但是这些东西从大体上看功能都差不多, 不得不说这是apple对发烧友的一种心里攻势. apple [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">
<p style="text-align: center;"><img class="aligncenter" title="新版touch" src="http://www.blogcdn.com/www.engadget.com/media/2009/09/touchmain1.jpg" alt="" width="400" height="533" /></p>
<p style="text-align: left;">话说apple 09.09.09的发布会 Rock n&#8217; Roll,看来苹果选的日子也不错阿, 殊不知地球这边就一个北京就有近20000对情侣喜结连理. 发布会之前, 我又一个想法, 当3代touch配上3GS的处理器和内存, 还有摄像头和mic, 我就入个touch+any andorid手机来代替我的iphone. 哈哈, 可惜apple不会这么傻, 最起码没我这么梦幻. 这不是技术问题吧? Maybe,之前听说了touch有技术问题没有解决. 但我觉得, 这就是apple的经营理念, apple不傻, 真的出了个那么牛逼的touch, 除了打电话什么都和iphone一样了而价格又第很多, 人们确实都会像我一样 touch+any phone = iphone的. apple就是想告诉我们,我们的产品是没有完美的, 如果想完美,那价格也一定不是完美的, touch+phone ≠ <a href="http://cyher.net/tag/iphone" class="st_tag internal_tag" rel="tag" title="标签 iphone 下的日志">iphone</a> 3GS. 或许, touch+nano+phone = <a href="http://cyher.net/tag/iphone" class="st_tag internal_tag" rel="tag" title="标签 iphone 下的日志">iphone</a> 3GS,但是价格也是划等号的, 为什么我们不选又小又cool 的 <a href="http://cyher.net/tag/iphone" class="st_tag internal_tag" rel="tag" title="标签 iphone 下的日志">iphone</a> 3GS.</p>
<p style="text-align: left;">经过上面的分析, apple其实不会那么傻的, 他每次做产品, 定价和功能总能对应, 并且让你难以选择, 功能没有强大多少,但是你需要, 价格提高的幅度也让你难以抉择. 哈哈,到现在你就中了apple的心里陷阱了, 现在你明白了, 为什么果粉,总是有很多apple的设备, 但是这些东西从大体上看功能都差不多, 不得不说这是apple对发烧友的一种心里攻势. <a href="http://cyher.net/tag/apple" class="st_tag internal_tag" rel="tag" title="标签 apple 下的日志">apple</a> 总是让人又爱又恨.</p>
<p style="text-align: left;">等? 你错了, apple对等待他产品的人,会有更”严厉的惩罚”, 当你等到了 带设想头的touch的时候, iphone 3GS已经降价了或者出了个iphone 3G AS(Advanced Slim), 你到时候觉得疯了, 然后不顾一切的买了最新的 iphone 3G AS. 你的腰包被掏空, apple一样不少赚.</p>
<p style="text-align: left;">哈哈, 没事干分析自己的心情, 可能大多数人不会这样想,但是我见过的果粉,基本都是比我疯狂的.最后重申,只有一件apple的产品的绝对不是果粉, 因为如果你买了一件apple的东西,你会发现, 另一件产品和你有的这件原来配合的这么好,然后你就成了果粉,你不得不说apple东西好(确实也不错),要不你不是扇自己脸么.至于那些没有买第2件的, 你只是把iphone当成手机, touch当成mp4, nano当成mp3, mac当成pc了.</p>
<p style="text-align: left;">结束, 不能再说了,再说又开始给apple做广告了&#8230;&#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://cyher.net/apple/apple_is_not_stupid/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

