伪造?还是检测信用卡 cocoa, Objc实现

伪造? 还是去检测一张信用卡? 看完这个图, 相信很容易了解其中的数学算法.

原始链接: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
20
21
22
23
24
25
26
27
28
29
The Luhn Mod-10 Method (ISO 2894/ANSI 4.13) involves a check digit in the
one's position.  The check digit is calculated starting at the right with
the digit immediately preceding the check digit (ten's digit) and moving
toward the left, doubling every other digit.  If a doubled digit is greater
than nine, the two digits are added to together to obtain a single-digit
result.  The sum of all the resulting digits (including those skipped) is then
taken modulo with 10, to obtain the check digit.
 
Below, is untested code.
 
/************************************************************************
*  LuhnMod10 - self-checking scheme for validating card account numbers
*  according to ISO 2894/ANSI 4.13.
*
*    Ex:  cardNumber = "795102879015546"
*         strlen(cardNumber) == 15
*         LuhnMod10(cardNumber, 14) == 6 == cardNumber[14]
*
************************************************************************/
int LuhnMod10(char* cardNumber, int size)
{
  static int table[2][10] = { {0,1,2,3,4,5,6,7,8,9}, {0,2,4,6,8,1,3,5,7,9} };
 
  for (int i=size-1, odd=0, sum=0; i>=0; i--)
    if (isdigit(cardNumber[i]))
      sum += table[(odd=1-odd)][cardNumber[i]-'0'];
  sum %= 10;
  return (sum ? 10-sum : 0);               /* return the check digit */
}

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

CheckCreditCard.h

1
2
3
4
5
6
7
8
9
#import 
 
@interface CheckCreditCard : NSObject {
	IBOutlet NSTextField *ccNum;
	IBOutlet NSTextField *ccTrue;
 
}
- (IBAction)checkIt:(id)sender;
@end

CheckCreditCard.m

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
//  CheckCreditCard.m
//  Verify Credit Card
//
//  Created by cyher on 11-3-8.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//
 
#import "CheckCreditCard.h"
 
@implementation CheckCreditCard
 
- (id)init
{
	[super init];
	NSLog(@"Init!");
	return self;
}
 
- (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;
 
	NSString *string = [ccNum stringValue];
	NSLog(@"ccNum = %@", string);
	if ([string length] == 0)
		return;
	for (int i = [string length] - 1; i >= 0; i--)
		sum +=
		sumTable[flip++ & 0x1][[string characterAtIndex:i] - '0'];
	NSLog(@"sum = %d", sum);
	if (0 == (sum % 10)) {
		[ccTrue setStringValue:[NSString stringWithFormat
				       :@"This is a real Credit Card!",
				       [string length]]];
	} else {
		[ccTrue setStringValue:[NSString stringWithFormat
					:@"This is fake Credit Card!",
					[string length]]];
	}
 
	return;
}
 
@end

来我们看看在mac上的效果吧:

 

怎么样很简单吧, 如果我们能够调用goggle(google的图形识别程序,基于云计算)的API,我们能够从图片转换成数字。其实一个有意思的小软件就成了. 希望我们能运用生活中的小科技, 来改变我们的生活吧.

 

 

用syerngy共享屏幕和键盘鼠标,超级KVM

自己在公司里写了个syerngy简单的介绍,觉得挺好的,就发上来了,英语不好,凑合看吧。这里介绍了ubuntu和windows互联,其实这个软件的特点就是多系统,windows,mac,linux都可以,如果有两台以上电脑很推荐此软件。
Would you want improve work efficiency?
Do you dislike there is not only one mouse on your desk?
Did you want share clipboard data between different OS, easily?
If have YES in your answers, haha, let’s begin!

Ok. Shortly, Synergy!! Synergy is a software.
here is it’s website:
STEP:
On the Client
Windows is a Client, So download this:
Install this.
  1. choose “Use another computer’s shared keyboard and mouse [client]“
  2. Type your pc’s host name, you can find it with this command “uname -n”
  3. Press start.
OK, That is all.
On the Server
Follow these steps on the computer with the keyboard and mouse.

Install QuickSynergy:

In Software Center, search “QuickSynergy”.
Open it (under Applications > Accessories)
Under the ‘Share’ tab enter the hostname or IP address of the Client machines in one of the directional boxes. The directional box you choose will determine which edge of the Host computer’s screen the mouse will “run off”.
Click Execute
Move the mouse to the edge of the Host screen — it should now appear on the client screen.
OK ,Have fun….
refer:
延伸:想在win7上用的更爽就看看了

Android 手机电源管理实例 – milestone

MOTO Milestone (omap)HTC tattoo (msm7225)HTC Magic (msm7201A)某手机(保密)(msm7227)
开机过程200ma-1000ma200ma-500ma
HSDPA 联网700ma500ma
idle, 屏幕最暗, 黑色背景,键灯关44ma13ma33ma60ma
idle, 屏幕中等, 黑色背景,键灯关69ma64ma73ma88ma
idle, 屏幕最亮, 黑色背景,键灯关104ma97ma135ma120ma
idle, 屏幕最暗, 动态桌面,键灯关330ma
idle, 屏幕中等, 动态桌面,键灯关350ma
idle, 屏幕最亮, 动态桌面,键灯关450ma
idle, 屏幕最暗, 白背景,键灯关51ma
idle, 屏幕中等, 白背景,键灯关92ma
idle, 屏幕最亮, 白背景,键灯关167ma
照相机预览400ma-500ma(1G)
325ma-350ma(550M)
210ma-260ma295ma-334ma
录制音频(开屏)107ma-112ma
录制音频(关屏)43ma-59ma
录制视频500ma-700ma(1G)
427ma-558ma(550M)
260ma-360ma360ma-390ma
google maps(gps开)540ma-750ma
浏览网页(HSDPA)(有数据链接时)400ma-600ma
浏览网页(EDGE)(有数据链接时)200ma-500ma
开屏,放mp3,耳机90ma-120ma168ma-220ma285ma
关屏, 放mp3,耳机30ma-50ma93ma-112ma210ma
开屏, 放mp4,耳机(放自己拍摄的)250ma-300ma300ma-327ma
开启g-sensro和gps320ma
wifi扫描时150ma
开led闪光灯(长亮)50ma(单独计算)
虚拟按键led20ma(单独计算)14ma
GSM通话(开接近)350ma-450ma
suspend(关屏进入休眠)2ma1ma1ma2ma

这样的房,这样的车,这样的女人(阿哈哈)

x:  什么是房子, 什么是车, 连老爹的女人都霸占了.

1x: 住老爹的房, 坐老爹的车, 连泡妞都用老爹的钱

2x: 和别人拼房, 和别人拼车, 连女朋友都和别人拼.

3x: 开二手车, 住二手房, 连媳妇都是二手的.

4x: 开上新车了, 住上大房子了, 连媳妇都都不止一个了.

5x: 开不动车了, 上不动楼了, 连孩子都说我不是亲爹了.

6x: 给孩子买车, 给孩子买房, 连儿媳妇都要帮着去相了.

7x: 车坏了, 房拆了, 连给自己买个墓地都要排号了.

8x: 再也不需要车了, 也不需要房了,连自己是生是死都不重要了.

可以说真的是闲着没事干, 才写了这样的话. 是挺消极的, 但是…..改变,还是顺从?

macbook pro ubuntu10.4 bcm无线网卡问题修复

话说虽然用了macbook pro成了apple fan但是也没有使我对linux的热情衰减, 这不刚刚把macbook pro上的9.10升级为10.4, 这回我相信ubuntu的自动升级能力,但是结果是,我不应该像要求mac os x一样要求 。 有几个东西不能用了,但是那也无关紧要,最要命的使我的wireless的驱动没了,装不上了,靠。这个我受不了。找到了以下解决方法。

首先,说明一点,我的电脑是macbook pro 471,就是macbook pro 5,1.

本来是应该这样解决

System->Administration->Hardware Drivers. Select the Broadcom STA options and click enable.

但是现在不行了。

1. 下载broadcom驱动源码,http://www.broadcom.com/support/802.11/linux_sta.php

2. 解压,然后找到 src/wl/sys/wl_.c 这个文件

3. 在 #include <XX.h>的下面一行加上下面的代码

#include <linux/sched.h>

4. 编译源码  make

5.把新编译的driver放到lib中

sudo mv wl.ko /lib/modules/$(uname -r)/kernel/drivers/net/wireless

6. 更新依赖关系

sudo depmod -a

7. ok 加入内核
modprobe wl
8. 如果编译报 没有include <linux/sched.h> 加入新的内核头文件。

sudo apt-get install linux-headers-$(uname -r)

到这里基本上就ok了 可以继续自由自在了,至于以后升级内核从新来一遍就ok

分类目录

music