Visit Our UNIX and Linux User Community


Encryption of card number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Encryption of card number
# 1  
Old 08-06-2009
Encryption of card number

i have a file with a : separated sections


Code:
ABC::2110.49:2110.49:31034050545::+DEF:FPT:2:N::::1:42.99:0.00:2008-07-11:CN:4658582030164342::1:N:afram:N:AI:00220600:S3FA'
XYZ:31034050694:3:::TFY:1:TL1::D:N:42.99:P:9:S:1:18.21:Y:0.00'
JKI:::OC::D:N:2.00::::2::Y::::::2008-07-11'

here 4658582030164342 is a card number(16 digits) i need to encrypt the number such that only first four and last six digit are
visible, that is the remaining six digit to be replaced by ******. that is
Code:
4658******164342

The output need to be
Code:
ABC::2110.49:2110.49:31034050545::+DEF:FPT:2:N::::1:42.99:0.00:2008-07-11:CN:4658******164342::1:N:afram:N:AI:00220600:S3FA'
XYZ:31034050694:3:::TFY:1:TL1::D:N:42.99:P:9:S:1:18.21:Y:0.00'
JKI:::OC::D:N:2.00::::2::Y::::::2008-07-11'

The card number only appears in the +DEF subsection.
There are several such sections that appear in the file apart from the other data.

To summarise the requirement is check for all the DEF subsection in the file look for 11th field (: separated within DEF) or 16 digit numeric in
DEF section if found encrypt card number as above.

Kindly Advice

Last edited by Franklin52; 08-06-2009 at 06:45 AM.. Reason: adding code tags
# 2  
Old 08-06-2009
Ex. using awk with -F : options.

Block rule something like
Code:
/+DEF.*:CN:/ { ... }

Scanning fields ex. using for
Code:
 cardnumber=""
 for (f=1;f<=NF;f++) {
     if ( $f == "CN" ) { cardnumber=$(f+1) }
     }

Create result using substr:
Code:
 start=substr(cardnumber,1,4)
 end=substr(cardnumber,11,6)
 new=sprintf("%s******%s",start,end)

# 3  
Old 08-06-2009
As ,

Kshj said :


Code:
awk -F":" 'BEGIN {OFS=":"} $0 ~/\+DEF.*CN/ {for(i=1;i<=NF;i++) { if($i=="CN"){$(i+1)=substr($(1+i),1,4)"******"substr($(1+i),11,16)}}}1' file_name.txt

# 4  
Old 08-06-2009
Thanks a lot but the issue is here we are checking with DEF section till CN but CN is not the fix two characters that will appear there
it can be any two character

So we have to check for the either the 11th field within DEF separated by : or 16 digit numeric word that appear within DEF section

---------- Post updated at 05:42 AM ---------- Previous update was at 05:38 AM ----------

Additionally it is not that in every DEF section we may get card number, if there is any other data(we can identify it if it is not 16 digit Numeric) we don't need to encrypt
# 5  
Old 08-06-2009
Just a bit modification to the above script :
Code:
awk -F":" 'BEGIN {OFS=":"} $0 ~/\+DEF/ {for(i=1;i<=NF;i++) { if($i=="+DEF"){$(i+12)=substr($(12+i),1,4)"******"substr($(12+i)
,11,16)}}}1' file_name.txt

As i checked , the number is the 12th filed from DEF.
# 6  
Old 08-06-2009
Hi Panyam,

its right it is the 12th field but the above code is not working and not encrypting.

---------- Post updated at 06:50 AM ---------- Previous update was at 06:41 AM ----------

Apologise there was an error on my part the above code worked wonder
Thanks a lot panyam and kshijSmilie

---------- Post updated at 08:37 AM ---------- Previous update was at 06:50 AM ----------

Last requirement Smilie

i need to encrypt only if the field length is greater than 15

Please Advice
# 7  
Old 08-06-2009
A bit change as follows:

Code:
awk -F":" 'BEGIN {OFS=":"} $0 ~/\+DEF/ {for(i=1;i<=NF;i++) { if($i=="+DEF"){if(length($(i+12))>=15) { $(i+12)=substr($(12+i),1,4)"******"substr($(12+i),11,16)}}}}1'

Not tested.

Previous Thread | Next Thread
Test Your Knowledge in Computers #332
Difficulty: Easy
It is possible to format a write-protected DVD-R hard disk.
True or False?

9 More Discussions You Might Find Interesting

1. Cybersecurity

File encryption tools with MAC address as an encryption key

Hi all, I'm looking for secure file encryption tools that use MAC address as encryption key. FYI, I'm using Red Hat Enterprise Linux OS. For example: when A wants to send file to B A will encrypt the file with B's computer MAC/IP address as an encryption key This file can only be decrypted... (2 Replies)
Discussion started by: sergionicosta
2 Replies

2. Programming

RSA encryption

Hi everybody, I know this is a linux forum but I've got a question about encryption. If you want to encrypt (and decrypt) more than one byte at a time do you have to choose sufficiently large numbers when generating the keys for the math to work out? Every example I've come across on the internet... (5 Replies)
Discussion started by: vindy
5 Replies

3. UNIX Desktop Questions & Answers

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card?

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card? Does any Linux OS support Nvidia card? (1 Reply)
Discussion started by: sito
1 Replies

4. HP-UX

how can I determine which NIC card is virtual NIC Card

how can I determine which NIC card is virtual NIC Card which condition can make a decision Does HP UX have Virtual Network Adapter Concept if ,it has where I can Find if I Install Virutal Network Adapter or which command that i can get it or which software can generate thanks (2 Replies)
Discussion started by: alert0919
2 Replies

5. UNIX for Dummies Questions & Answers

Encryption on SCO

Can someone help me please. I have a database that we backup using cpio. Is there an encryption option that I could use when taking this backup. Thanks in advance for any help. (0 Replies)
Discussion started by: mandarin
0 Replies

6. IP Networking

no encryption type specified

Hi I have created a user in snmpv3 as myuser n gave a password. Its also feching data by snmpget. Then I created another user as arika and the password is same as myuser.. Now I am trying to change the password by the command : snmpusm -v 3 -u arika -l authNoPriv -a MD5 -A my_password... (1 Reply)
Discussion started by: swapna_me
1 Replies

7. UNIX for Advanced & Expert Users

pgp encryption

Hi I have one script for doing the gpg encryption on linux. The encrytion is doing fine when i am running the script from command prompt on linux The same script when it is triggering from mainframe using sysopts option in NDM(connect direct) the encryption step in the shell script is... (0 Replies)
Discussion started by: Arvind Maurya
0 Replies

8. UNIX for Dummies Questions & Answers

File encryption/Key encryption ????

My dilemma, I need to send, deemed confidential, information via e-mail (SMTP). This information is sitting as a file on AIX. Typically I can send this data as a e-mail attachment via what we term a "mail filter" using telnet. I now would like to somehow encrypt the data and send it to a e-mail... (1 Reply)
Discussion started by: hugow
1 Replies

9. Shell Programming and Scripting

encryption is possible??

NEED expertise help for this topic!!! Question 1: Is encryption possible for the shell scriping programing? shadow the scriping file, do think is impossible... Question2: built a simple program with the simplicity function that allow user change settings by enter corret name and... (3 Replies)
Discussion started by: trynew
3 Replies

Featured Tech Videos