cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Sarazin73 Frequent Visitor
Frequent Visitor

Decrypt string values from a column of a table in a query

Hello,
i search to decrypt string values from a crypted column on a table imported as a query in my Power BI report.
The string is crypted in input with a XOR algorythm as follow :

String ToCrypt="";

for (int i=0; i< "sample_string".length();i++) {
           ToCrypt = ToCrypt + (char)("sample_string".charAt(i)^24); //(XOR 24)
}

How can i do in Power Query to decrypt in a new column the content of this crypted column for each row of my query ? (dataset). Thank you for yours ideas and comments

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Re: Decrypt string values from a column of a table in a query

Hi @Sarazin73,

I've written a custom function for you:

fnXorCrypt = (
    string as text, 
    xorValue as number
) as text =>
    // concat encrypted characters
    List.Accumulate(
        // get a list of chars
        Text.ToList(string),
        // initial string
        "",
        // accumulate last state and a new encrypted character
        (state, current) =>
            state 
            & 
            Character.FromNumber(
                Number.BitwiseXor(
                    Character.ToNumber(current), 
                    xorValue
                )
            )
    )

The usage:

EncodedString = fnXorCrypt("Lundi", 42)

A test:

Capture.PNG

 

View solution in original post

4 REPLIES 4
Highlighted
Super User II
Super User II

Re: Decrypt string values from a column of a table in a query

Hi @Sarazin73,

do you also have the decryption algorithm in c-like code? If I had one, I'd develop a function in M for you.

And can you please post some examples for testing?

Thank you 🙂

 

Sarazin73 Frequent Visitor
Frequent Visitor

Re: Decrypt string values from a column of a table in a query

Hi,

 

Thanks for helphing me !
The algorythm used is the same to decryt than to encrypt. The initial outside script that crypt data as source is in java language. We have finally do tests with XOR 42 instead of XOR 24. Below, some samples with their corresponding encoding string.

Lundi : f_DNC

Mardi : gKXNC

Mercredi : gOXIXONC

Jeudi : `O_NC

Vendredi : |ODNXONC

Samedi : yKGONC

Dimanche : nCGKDIBO

Super User II
Super User II

Re: Decrypt string values from a column of a table in a query

Hi @Sarazin73,

I've written a custom function for you:

fnXorCrypt = (
    string as text, 
    xorValue as number
) as text =>
    // concat encrypted characters
    List.Accumulate(
        // get a list of chars
        Text.ToList(string),
        // initial string
        "",
        // accumulate last state and a new encrypted character
        (state, current) =>
            state 
            & 
            Character.FromNumber(
                Number.BitwiseXor(
                    Character.ToNumber(current), 
                    xorValue
                )
            )
    )

The usage:

EncodedString = fnXorCrypt("Lundi", 42)

A test:

Capture.PNG

 

View solution in original post

Sarazin73 Frequent Visitor
Frequent Visitor

Re: Decrypt string values from a column of a table in a query

Hi NoLock,

thanks for your job. It's perfect !

Helpful resources

Announcements
Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors