Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: regex for identifying encrypted text

by james28909 (Deacon)
on May 16, 2018 at 16:44 UTC ( #1214668=note: print w/replies, xml ) Need Help??


in reply to regex for identifying encrypted text

Can you give an example file that you parse? I would say you could just change the input record separator to paragraph mode eg  local $/ = ""; when you find "set private-key ", then read one more time with <DATA>. I am not sure if enc data ends with '[...]' or "\n\n" or '"' or what.

please post an example file.
#here is a small test i did with the examples given in OP use strict; use warnings; while(<DATA>){ if ( /set private-key/){ print "\nsetting input seperator to paragraph mode\n"; local $/ = ""; #record separator will change itself back to de +fault AFTER leaving the if block print "skipping encrypted data\n"; <DATA>; print "encrypted data skipped and should not be printed !\n\n" +; next; } print if /\w+/; } __DATA__ random data more random data blah blah one last test BEFORE! encrypted data! set private-key "-----BEGIN ENCRYPTED PRIVATE KEY----- sdfkjghsdlkhfgldkfjghldkfjgh sdflkjgdfgl;kd;lfkgjdlfkgjd;l dlkjfghlkdfjghldskfjhgldskfjhg this is AFTER encrypted data more rand0m data this is the last test AFTER! encrypted data.
The idea here is to read the file/s one line at a time until you find the desired string. then once you find that string, change the input record separator to stop at the end of the enc data (if possible). if enc data is always the same length, then you could find the desired string and then read that static length every time.
EDIT: Cleaned up post... a little.

Replies are listed 'Best First'.
Re^2: regex for identifying encrypted text
by sundialsvc4 (Abbot) on May 16, 2018 at 20:49 UTC

    To my reading, the OP implies that the set private key command occurs in a single line which also includes the cipher payload complete with both brackets.   In that case, I think that I would expand upon my previously-suggested regex to include the command, the space and double-quote, and the cipher header bracket ... then proceeding non-greedily to the corresponding footer-bracket and the final quote, knowing that thereby you have got it all.   Substitute an empty-string for the whole thing, and the problem is solved.   Multi-line logic would be only slightly more complicated, and all of it can be buried within a subroutine so that the rest of the program doesn’t have to deal with it.   Because the brackets are there and can be relied-upon, the OP does not have to come up with a “regex for identifying encrypted text.”

    Just my two cents ...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214668]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2018-07-22 01:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (451 votes). Check out past polls.

    Notices?