Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.047 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'algorithm': 0.03; 'python': 0.09; 'calculating': 0.09; 'subject:number': 0.09; 'subject:using': 0.09; 'def': 0.10; 'resulting': 0.13; '(result': 0.16; 'document:': 0.16; 'isbn': 0.16; 'multiplied': 0.16; 'structure.': 0.16; 'used."': 0.16; 'wrote:': 0.17; 'team,': 0.18; 'code,': 0.18; 'trying': 0.21; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'table,': 0.29; 'url:cz': 0.29; 'url:download': 0.29; '"the': 0.29; 'becomes': 0.30; 'code': 0.31; 'could': 0.32; '"")': 0.33; 'like:': 0.33; 'to:addr:python-list': 0.33; 'code:': 0.33; 'false': 0.35; 'pm,': 0.35; 'something': 0.35; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'rather': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'apply': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'mentioned': 0.63; 'here': 0.65; 'validate': 0.65; 'account': 0.67; 'direct': 0.69; 'banks': 0.71; 'received:74.208': 0.71; '11.': 0.81; '10th': 0.84; '2.7.': 0.84; 'subject:Verification': 0.84; 'url:export': 0.84; 'norway': 0.91; 'divided': 0.93 Date: Tue, 19 Feb 2013 16:10:54 -0500 From: Dave Angel User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Verification of bank number using modulus 11 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Provags-ID: V02:K0:eF/20iv1gh53W0h7mAi9VC7ml9cUObuaeebMfEelZRy meQxXgtxaQAHILjVK0TMWwjzGKlHcDF8WH327oYg1kASSf7403 HZzvViZvT1pAM2KByO/hARBR3lmUZCQ/m6h8Aa1QxOWKdv4mGB X7wkAWIuxNUvhUI0NNW2DPakPRy6jMz9chakLjOaWYxZiRxhWU Be0zK/F2awkuheGzOTqWVsqUVAB1aPYCUGbZFNn1egG18zPWL2 z49jMCPNOR6+hSiBRkCCImGuhhNpnI8/GiHWd1prvP+kS2r9Zu pVMx0CuKVpylYNGrsp0wwT+RqWGFBr0yIZS5XtWxE4xButjKQ= = X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361308267 news.xs4all.nl 6908 [2001:888:2000:d::a6]:35426 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39276 On 02/19/2013 03:50 PM, Morten Engvoldsen wrote: > Hi Team, > I am trying to verify the account number using the following algorithm: > > "The valid account number is 11 numeric digit without seperator. Eg. > 86011117947 is a valid account number. All banks apply a modulus-based > method for the validation of the account structure. The 10-digit account > number is multiplied from left to right by the following weights: 5, 4, 3, > 2, 7, 6, 5, 4, 3, 2. The resulting numbers are added up and divided by 11. > The remainder is subtracted from 11 and becomes the check digit. If the > remainder is 0, the check digit will be 0. If digits 5 and 6 of the account > number are zeros, the check digit is calculated on the 7, 8, 9 and 10th > digit of the account number. Account numbers for which the remainder is 1 > (check digit 10) cannot be used." > > I am trying to validate the Norway account number using the algorithm > mentioned in the following document: > http://www.cnb.cz/miranda2/export/sites/www.cnb.cz/cs/platebni_styk/iban/download/TR201.pdf > > Here is my code: > def calc_checkdigit(isbn): > isbn = isbn.replace(".", "") > check_digit = int(isbn[-1]) > isbn = isbn[:-1] > if len(isbn) != 10: > return False > result = sum((10 - i) * (int(x) if x != 'X' else 10) for i, x in > enumerate(isbn)) > return (result % 11) == check_digit > > calc_checkdigit(""8601.11.17947"") > > In my program : it is calculating 10 digit with weights 10-1, but according > to above algorithm the weights should be : 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. > > Could you please let me know how can i calculate the 10 digit with weights > 5, 4, 3, 2, 7, 6, 5, 4, 3, 2. I am using python 2.7. > Without analyzing your code, the direct answer to your code would be to make a table, something like: weights = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2] and multiple by weights[i] rather than (10-i) -- DaveA