Home » Kamasutra Cipher with Digits

Kamasutra Cipher with Digits

Kamasutra Cipher 2 – Generate 13 random pairs from English alphabets and 5 random pairs from 0-9 digits and use that to encrypt the plain text. Since. this is random pairing, hence answers of all of us will be different. Any other character other than English alphabet and number digits will not be changed. Ex. I generated following pairs (pairs in two rows for sake of illustration) izqurplxwtvej ancgfoybksdhm 28390 57641 Hence, i will be replaced with a and vice versa, z will be replaced with n and vice versa, 2 with 5 and vice versa and so on. Plain Text – b3arb@arian9s $marchi56ng Encrypted Text – x6ifx@ifaiz4t $jifqea23zu

📌 Challenge Details and Links
ExcelBI Excel Challenge Number: 388
Challenge Difficulty: ⭐️⭐️⭐️
📥Download Sample File
📥Link to the solutions on LinkedIn

Solving the challenge of Kamasutra Cipher with Digits with Power Query

Power Query solution 1 for Kamasutra Cipher with Digits, proposed by Luan Rodrigues:
let
 Fonte = Tabela1,
 list = List.Zip({{"0".."9", "a".."z"},List.Sort({"0".."9", "a".."z"}, each Number.From(_>"9") + Number.Random() )}),
 res = Table.AddColumn(Fonte, "tab", each Text.Combine(List.ReplaceMatchingItems(Text.ToList([Plain Text]),list )))
in
 res


                    
                  
          
            

  
                  
    
      
        Show translation
      
      
        Show translation of this comment

Solving the challenge of Kamasutra Cipher with Digits with Excel

Excel solution 1 for Kamasutra Cipher with Digits, proposed by Bo Rydobon 🇹🇭:
=LET(
    s,
    SEQUENCE(
        36
    )-1,
    b,
    SORTBY(
        LOWER(
            BASE(
                s,
                36
            )
        ),
        s>9,
        ,
        RANDARRAY(
        36
    ),
        
    ),
    MAP(
        A2:A11,
        LAMBDA(
            a,
            LET(
                m,
                MID(
                    a,
                    SEQUENCE(
                        LEN(
                            a
                        )
                    ),
                    1
                ),
                CONCAT(
                    IFNA(
                        XLOOKUP(
                            m,
                            b,
                            SORTBY(
                                b,
                                s>9,
                                ,
                                -s,
                                
                            )
                        ),
                        m
                    )
                )
            )
        )
    )
)
Excel solution 2 for Kamasutra Cipher with Digits, proposed by محمد حلمي:
=MAP(
    A2:A10,
    LAMBDA(
        A,
        LET(
            S,
            SEQUENCE(
                26
            ),
            
            J,
            TAKE(
                S,
                10
            )-1,
            E,
            MID(
                A,
                SEQUENCE(
                    50
                ),
                1
            ),
            
            V,
            SORTBY(
                CHAR(
                    S+96
                ),
                RANDARRAY(
                26
            )
            ),
            X,
            SORTBY(
                J,
                
                RANDARRAY(
                    10
                )
            ),
            CONCAT(
                IFNA(
                    XLOOKUP(
                        E,
                        ""&
                        VSTACK(
                            V,
                            X
                        ),
                        VSTACK(
                            SORTBY(
                                V,
                                -S
                            ),
                            SORTBY(
                                X,
                                -J
                            )
                        )
                    ),
                    E
                )
            )
        )
    )
)
Excel solution 3 for Kamasutra Cipher with Digits, proposed by محمد حلمي:
=BASE(
    SEQUENCE(
        36
    )-1,
    36
)
Excel solution 4 for Kamasutra Cipher with Digits, proposed by Julian Poeltl:
=LET(
    L,
    CHAR(
        SEQUENCE(
            26,
            ,
            97
        )
    ),
    LL,
    CHAR(
        INDEX(
            UNIQUE(
                RANDARRAY(
                    26^2,
                    1,
                    1,
                    26,
                    1
                )
            ),
            SEQUENCE(
                26
            )
        )+96
    ),
    N,
    SEQUENCE(
        10,
        ,
        0
    ),
    NN,
    INDEX(
        UNIQUE(
            RANDARRAY(
                10^2,
                1,
                0,
                9,
                1
            )
        ),
        SEQUENCE(
            10
        )
    ),
    MAP(
        A2:A10,
        LAMBDA(
            A,
            TAKE(
                SCAN(
                    A,
                    SEQUENCE(
                        36
                    ),
                    LAMBDA(
                        A,
                        B,
                        SUBSTITUTE(
                            A,
                            INDEX(
                                VSTACK(
                                    L,
                                    N
                                ),
                                B
                            ),
                            INDEX(
                                VSTACK(
                                    LL,
                                    NN
                                ),
                                B
                            )
                        )
                    )
                ),
                -1
            )
        )
    )
)
Excel solution 5 for Kamasutra Cipher with Digits, proposed by Timothée BLIOT:
=LET(
    A,
    SEQUENCE(
        26
    ),
    B,
    SEQUENCE(
        10
    )-1,
    C,
    CHAR(
        SORTBY(
            A,
            RANDARRAY(
        26
    )
        )+96
    ),
    D,
    TEXT(
        SORTBY(
            B,
            RANDARRAY(
        10
    )
        ),
        0
    ),
    E,
    VSTACK(
        SORTBY(
            C,
            A,
            -1
        ),
        SORTBY(
            D,
            B,
            -1
        )
    ),
    F,
    VSTACK(
        C,
        D
    ),
    MAP(
        A2:A10,
        LAMBDA(
            z,
            CONCAT(
                MAP(
                    MID(
                        z,
                        SEQUENCE(
                            LEN(
                                z
                            )
                        ),
                        1
                    ),
                    LAMBDA(
                        x,
                        IFNA(
                            XLOOKUP(
                                x,
                                E,
                                F
                            ),
                            x
                        )
                    )
                )
            )
        )
    )
)
Excel solution 6 for Kamasutra Cipher with Digits, proposed by JvdV –:
=MAP(
    A2:A10,
    LAMBDA(
        x,
        LET(
            l,
            LOWER(
                BASE(
                    ROW(
                        1:36
                    )-1,
                    36
                )
            ),
            r,
            SORTBY(
                l,
                RANDARRAY(
                    36
                )
            ),
            s,
            MID(
                x,
                SEQUENCE(
                    LEN(
                        x
                    )
                ),
                1
            ),
            CONCAT(
                IFNA(
                    XLOOKUP(
                        s,
                        l,
                        SORTBY(
                            r,
                            r>"9"
                        )
                    ),
                    s
                )
            )
        )
    )
)

Or:

=REDUCE(
    "",
    ROW(
        1:99
    ),
    LAMBDA(
        x,
        y,
        x&LET(
            l,
            LOWER(
                BASE(
                    ROW(
                        1:36
                    )-1,
                    36
                )
            ),
            r,
            SORTBY(
                l,
                RANDARRAY(
                    36
                )
            ),
            s,
            MID(
                B2:B10,
                y,
                1
            ),
            IFNA(
                XLOOKUP(
                    s,
                    l,
                    SORTBY(
                        r,
                        r>"9"
                    )
                ),
                s
            )
        )
    )
)
Excel solution 7 for Kamasutra Cipher with Digits, proposed by Giorgi Goderdzishvili:
=MAP(
    A2:A10,
    LAMBDA(
        x,
        LET(
            
            _cr,
            SORTBY(
                CHAR(
                    SEQUENCE(
                        26,
                        ,
                        97
                    )
                ),
                RANDARRAY(
                    26
                )
            ),
            
            _nm,
             SORTBY(
                 SEQUENCE(
                     10,
                     ,
                     0
                 ),
                 RANDARRAY(
                     10
                 )
             )&"",
            
            _gr,
             HSTACK(
                 VSTACK(
                     _cr,
                     _nm
                 ),
                 VSTACK(
                     TAKE(
                         _cr,
                         -13
                     ),
                     TAKE(
                         _cr,
                         13
                     ),
                     TAKE(
                         _nm,
                         -5
                     ),
                     TAKE(
                         _nm,
                         5
                     )
                 )
             ),
            
            _sp,
             CONCAT(
                 IFERROR(
                     VLOOKUP(
                         MID(
                             x,
                             SEQUENCE(
                                 ,
                                 LEN(
                                     x
                                 )
                             ),
                             1
                         ),
                         _gr,
                         2,
                         FALSE
                     ),
                     MID(
                             x,
                             SEQUENCE(
                                 ,
                                 LEN(
                                     x
                                 )
                             ),
                             1
                         )
                 )
             ),
            
            _sp
        )
    )
)
Excel solution 8 for Kamasutra Cipher with Digits, proposed by Diarmuid Early:
=LET(input,
     A2:A10,
    
 ltrNum,
     VSTACK(
          SEQUENCE(
              10,
              ,
              0
          ),
          CHAR(
              SEQUENCE(
                  26,
                  ,
                  CODE(
                      “A”
                  )
              )
          ) 
     ),
    
 rand,
     SORTBY(
         ltrNum,
          ISNUMBER(
              ltrNum
          ),
          1,
          RANDARRAY(
              36
          ),
          1
     ),
    
 oneWay,
     WRAPROWS(
         rand,
          2
     ),
    
 twoWay,
     HSTACK(
         oneWay,
          SORTBY(
              oneWay,
               {2,
              1}
          )
     ),
    
 allLtrs,
     IFERROR(
         MID(
             input,
              SEQUENCE(
                   ,
                   MAX(
                       LEN(
                           input
                       )
                   ),
                   1
              ),
              “”
         ),
         
          look,
          IFERROR(
              VLOOKUP(
                  allLtrs,
                   twoWay,
                   2,
                   0
              ),
               allLtrs
          ),
         
          cap,
          IF(
              EXACT(
                  allLtrs,
                  LOWER(
                      allLtrs
                  )
              ),
               LOWER(
                   look
               ),
               look
          ),
         
          out,
          BYROW(
              cap,
               CONCAT
          ),
         
          out
     )

The idea:
* ltrNum is a list of all letters and numbers
* sort first by ISNUMBER,
     then by a random array (to get shuffled letters and numbers separately)
* wrap in rows of two to get pairs of letters (and stack that array over the same thing with the columns swapped to get the reverse direction)
* split the input into letters (I can’t remember if the IFERROR is needed here) - this gives a 2-D array where each row is one input sentence,
     and the nth column is the nth letter
* look each letter up in the lookup table (return itself if not found - for spaces / punctuation)
Excel solution 9 for Kamasutra Cipher with Digits, proposed by Diarmuid Early:
=LET(
    input,
     A2:A10,
    
     ltrNum,
     VSTACK(
          SEQUENCE(
              10,
              ,
              0
          ),
          CHAR(
              SEQUENCE(
                  26,
                  ,
                  CODE(
                      "A"
                  )
              )
          ) 
     ),
    
     rand,
     SORTBY(
         ltrNum,
          ISNUMBER(
              ltrNum
          ),
          1,
          RANDARRAY(
              36
          ),
          1
     ),
    
     oneWay,
     WRAPROWS(
         rand,
          2
     )&"",
    
     twoWay,
     VSTACK(
         oneWay,
          SORTBY(
              oneWay,
               {2,
              1}
          )
     ),
    
     allLtrs,
     IFERROR(
         MID(
             input,
              SEQUENCE(
                   ,
                   MAX(
                       LEN(
                           input
                       )
                   )
              ),
              1
         ),
          ""
     ),
    
     look,
     IFERROR(
         VLOOKUP(
             allLtrs,
              twoWay,
              2,
              0
         ),
          allLtrs
     ),
    
     cap,
     IF(
         EXACT(
             allLtrs,
             LOWER(
                 allLtrs
             )
         ),
          LOWER(
              look
          ),
          look
     ),
    
     out,
     BYROW(
         cap,
          CONCAT
     ),
    
     out
)
Excel solution 10 for Kamasutra Cipher with Digits, proposed by Surendra Reddy:
=MAP(
    A2:A10,
    LAMBDA(
        x,
        LET(
            a,
            WRAPROWS(
                SORTBY(
                    CHAR(
                        SEQUENCE(
                            26,
                            ,
                            97
                        )
                    ),
                    RANDARRAY(
                        26
                    )
                ),
                2
            ),
            b,
            WRAPROWS(
                SORTBY(
                    SEQUENCE(
                        10,
                        ,
                        0
                    ),
                    RANDARRAY(
                        10
                    )
                ),
                2
            ),
            d,
            MID(
                x,
                SEQUENCE(
                    LEN(
                        x
                    )
                ),
                1
            ),
            z,
            IFNA(
                XLOOKUP(
                    d,
                    INDEX(
                        a,
                        ,
                        1
                    ),
                    INDEX(
                        a,
                        ,
      &                  2
                    )
                ),
                d
            ),
            TEXTJOIN(
                ,
                ,
                IFERROR(
                    XLOOKUP(
                        z*1,
                        INDEX(
                            b,
                            ,
                            1
                        ),
                        INDEX(
                            b,
                            ,
                            2
                        )
                    ),
                    z
                )
            )
        )
    )
)

Solving the challenge of Kamasutra Cipher with Digits with Python in Excel

Python in Excel solution 1 for Kamasutra Cipher with Digits, proposed by John V.:
Hi everyone!
One [Python] option could be:
from random import random as r
n = map(chr, list(range(48, 58)) + list(range(97, 123)))
j = ''.join(sorted(n, key = lambda x: (x > "9") + r()))
a = [45 - i if i > 9 else 9 - i for i in range(36)]
[''.join(i if j.find(i) == -1 else j[a[j.find(i)]] for i in t) for t in xl("A2:A10")[0]]
Blessings!
                    
                  

Solving the challenge of Kamasutra Cipher with Digits with R

R solution 1 for Kamasutra Cipher with Digits, proposed by Konrad Gryczan, PhD:
library(tidyverse)
library(readxl)
input = read_excel("Excel/388 Kamasutra Cipher_2.xlsx", range = "A1:A10")
generate_code = function() {
 shuffled_alph = sample(letters)
 sh_p1 = shuffled_alph[1:(length(shuffled_alph)/2)] 
 sh_p2 = shuffled_alph[(length(shuffled_alph)/2 + 1):length(shuffled_alph)]
 sh_p1 = setNames(sh_p1, sh_p2)
 sh_p2 = setNames(sh_p2, sh_p1)
 code = c(sh_p1, sh_p2)
 
 shuffled_digits = sample(0:9)
 sh_d1 = shuffled_digits[1:(length(shuffled_digits)/2)]
 sh_d2 = shuffled_digits[(length(shuffled_digits)/2 + 1):length(shuffled_digits)]
 sh_d1 = setNames(sh_d1, sh_d2)
 sh_d2 = setNames(sh_d2, sh_d1)
 code = c(code, sh_d1, sh_d2)
 return(code)
}
code = function(string){
 code = generate_code()
 string = tolower(string)
 chars = map(words, str_split, "") %>%
 map(unlist)
 coded_chars = map(chars, function(x) code[x])
 coded_string = paste(coded_words, collapse = " ")
 return(coded_string)
}
result = input %>%
 mutate(coded = map_chr(`Plain Text`, code))
result
                    
                  

&&

Leave a Reply