Parolamı atla


17

Sık kullanılan sözcüklerin şifre olarak kullanılmasından kaçınılmalıdır. Bu zorluk munges belirli bir şifre (bu çok basit bir program kodlama hakkında M odify u ntil N yerine G uessed E asily).

Giriş

Alfabede yazılmış bir dize olan bir kelime abcdefghijklmnopqrstuvwxyz. Harflerin küçük veya büyük olması önemli değildir.

munging

  1. Aynı herhangi tekrar dizisini değiştirmek harf harf tekrarlandı sayısına göre önce kendisi için ( LLLLile 4L)
  2. İlkini aşununla değiştir:@
  3. İlkini bşununla değiştir:8
  4. İlkini cşununla değiştir:(
  5. İlkini dşununla değiştir:6
  6. İlkini eşununla değiştir:3
  7. İlkini fşununla değiştir:#
  8. İlkini gşununla değiştir:9
  9. İlkini hşununla değiştir:#
  10. İlkini işununla değiştir:1
  11. İkinci değiştirme iile!
  12. İlkini kşununla değiştir:<
  13. İlkini lşununla değiştir:1
  14. İkinci değiştirme lilei
  15. İlkini oşununla değiştir:0
  16. İlkini qşununla değiştir:9
  17. İlkini sşununla değiştir:5
  18. İkinci değiştirme sile$
  19. İlkini tşununla değiştir:+
  20. İlkini vşununla değiştir:>
  21. İkinci değiştirme vile<
  22. İlkini wşununla değiştir:uu
  23. İkinci değiştirme wile2u
  24. İlkini xşununla değiştir:%
  25. İlkini yşununla değiştir:?

Kural 1, daha fazla uygulanamayana kadar gereken sayıda uygulanmalıdır. Bundan sonra kuralların geri kalanı uygulanır.

Munged kelimesi çıktısı

Örnekler

  • codegolf -> (0639o1#
  • programming -> pr09r@2m1ng
  • puzzles -> pu2z135
  • passwords -> p@25uu0r6$
  • wwww -> 4uu
  • aaaaaaaaaaa -> 11a
  • lllolllolll -> 3103io3l
  • jjjmjjjj -> 3jm4j

Bu , bu yüzden programınızı mümkün olduğunca kısa yapın!

Bu yayındaki hiçbir şey şifre fikri olarak veya şifre uygulamalarının herhangi bir parçası olarak kullanılmamalıdır.


18
Bunun gibi programların mümkün olduğu gerçeği, saldırganın bunları yazabilmesi ve parolayı yapıştırabilmesi (ve çeşitli mühimmatları denemesi) kadar kolay (daha kolay bir donanıma sahip oldukları için daha da kolay) anlamına gelir. Yani sadece güvenlik uğruna şunu söyleyeceğim: bu yazıdaki hiçbir şey şifre fikri olarak veya şifre uygulamalarının herhangi bir parçası olarak kullanılmamalıdır.
NH.

1
Bu yasal uyarıyı kalınlaştırmanızı ve en üstte çoğaltmanızı öneririm. Asla çok dikkatli olamaz ...
wizzwizz4

Yanıtlar:


11

Java 8, 237 321 319 280 247 241 240 237 bayt

s->{for(int a[]=new int[26],i=0,l=s.length,t,x;i<l;i+=t){for(t=0;++t+i<l&&s[i]==s[t+i];);System.out.print((t>1?t+"":"")+(++a[x=s[i]-65]>2?s[i]:"@8(63#9#1J<1MN0P9R5+U>u%?ZABCDEFGH!JKiMNOPQR$TU<2XYZ".charAt(x+26*~-a[x])+(x==22?"u":"")));}}

+84 bayt, çünkü kurallarda değişiklik var .. ( EDIT: Sonunda benim ilk 237 bayt geri. ) Java WWWWile değiştirmek 222Wkolay, ama 4Wdeğil .. Sadece Java regex yakalama grubu bir şey için kullanmak için bir yol olsaydı. Uzunluğun elde edilmesi "$1".length(), eşleşmenin kendisiyle değiştirilmesi, eşleşmenin "$1".replace(...)tamsayıya dönüştürülmesi new Integer("$1")veya Retina (ie s.replaceAll("(?=(.)\\1)(\\1)+","$#2$1")) veya JavaScript (ie s.replaceAll("(.)\\1+",m->m.length()+m.charAt(0))) gibi bir şey kullanılması, Java'da görmek istediğim 1 numaralı şey olacaktır. Codegolfing faydalanmak için gelecek ..>.> Sanırım bu Java'nın yakalama grubu maçında hiçbir şey yapamadığım 10 + + zaman .. @ OlivierGrégoire
sayesinde -78 bayt .

G / Ç büyük harftir.

Açıklama:

Burada deneyin.

s->{                           // Method with String parameter and no return-type
  for(int a[]=new int[26],     //  Array with 26x 0
          i=0,                 //  Index-integer, starting at 0
          l=s.length,          //  Length
          t,x;                 //  Temp integers
      i<l;                     //  Loop (1) over the characters of the input
      i+=t){                   //    After every iteration: Increase `i` by `t`
    for(t=0;++                 //   Reset `t` to 1
        t+i<l                  //   Inner loop (2) from `t+i` to `l` (exclusive)
        &&s[i]==s[t+i];        //   as long as the `i`'th and `t+i`'th characters are equal
    );                         //   End of inner loop (2)
    System.out.print(          //   Print:
     (t>1?t+"":"")             //    If `t` is larger than 1: print `t`
     +(++a[x=s[i]-65]>2?       //    +If the current character occurs for the third time:
       s[i]                    //      Simply print the character
      :                        //     Else:
       "@8(63#9#1J<1MN0P9R5+U>u%?ZABCDEFGH!JKiMNOPQR$TU<2XYZ".charAt(x
                               //      Print the converted character at position `x`
        +26*~-a[x])            //       + 26 if it's the second time occurring
       +(x==22?"u":"")));      //      And also print an additional "u" if it's 'W'
  }                            //  End of loop (1)
}                              // End of method

10

JavaScript (ES6), 147 bayt

s=>[[/(.)\1+/g,m=>m.length+m[0]],..."a@b8c(d6e3f#g9h#i1k<l1o0q9s5t+v>x%y?i!lis$v<".match(/../g),["w","uu"],["w","2u"]].map(r=>s=s.replace(...r))&&s

Test Durumları

açıklama

Giriş dizesinde, ssınama tarafından belirtilen sırayla bir dizi yerine geçer . Serideki her öğe, daha sonra yayılan ( ...r) ve geçirilen iki öğe içeren bir dizi veya dizedir s.replace().

s=>[
    [/(.)\1+/g, m=>m.length + m[0]],// first replacement: transform repeated letters
                                    // into run-length encoding

                                    // string split into length-2 partitions and
                                    // spread into the main array
    ..."a@b8c(d6e3f#g9h#i1k<l1o0q9s5t+v>x%y?i!lis$v<".match(/../g),
                                    // next replacements: all single-char replacements.
                                    // "second" versions are placed at the end so they
                                    //    replace the second instance of that char

    ["w","uu"],["w","2u"]           // last replacements: the two "w" replacements
]
.map(r=> s = s.replace(...r))       // run all replacements, updating s as we go
&& s                                // and return the final string

Very good answer
mdahmoune

6

05AB1E , 69 bayt

Emigna sayesinde -9 bayt

γvygD≠×yÙ}J.•k®zĀÒĀ+ÎÍ=ëµι
•"@8(63#9#1<1095+>%?!i$<"ø'w„uu„2u‚â«vy`.;

Çevrimiçi deneyin!


Kullanabilirsiniz'w„uu„2u‚â
Emigna

Plz girdi olarak wwww için sonucu doğrulayabilir misiniz?
mdahmoune

@mdahmoune Çıktılar4uu
Okx

@Emigna Kartezyen ürün, iyi fikir.
Okx

İlk bölüm olabilirγvygD≠×yÙ}J
Emigna

6

Perl 5 , 152 + 1 ( -p) = 153 bayt

s/(.)\1+/(length$&).$1/ge;%k='a@b8c(d6e3f#g9h#i1j!k<l1mio0q9r5s$t+u>v<x%y?'=~/./g;for$i(sort keys%k){$r=$k{$i};$i=~y/jmru/ilsv/;s/$i/$r/}s/w/uu/;s/w/2u/

Çevrimiçi deneyin!


Plz ne demek istiyorsun (-p)?
mdahmoune

1
mdahmoune -p, perlkomut dosyasının sonundaki girdiyi STDINve printiçeriğini otomatik olarak okuyan komut satırında argüman olarak kullanılır $_. TIO bu seçeneğe izin verir ve bir ek bayt olarak sayıldığından perl -pe<code>1 bayt fazla olduğundan perl -e<code>.
Dom Hastings

Ben olmamalıdır, bir yazım hatası yaptığınızı düşünüyorum ~arasındaki j~kbir olmak !yerine? Şu anda yerine ikinci ikinci yerine ia ~yerine !.
Kevin Cruijssen

@Xcali #testingonproduction
NieDzejkob

2
@NieDzejkob Daha iyi bir yer yok. Üretimde çalışacağını bilmenin tek yolu bu.
Xcali

4

Muhtemelen en golfed değil, ama çalışıyor.

Ovs sayesinde -6 bayt

-77 NieDzejkob ve Jonathan French sayesinde bayt

Python 3 , 329323 bayt 246 bayt

import re;n=input()
for a in re.finditer('(\w)\\1+',n):b=a.group();n=n.replace(b,str(len(b))+b[0],1)
for A,B,C in[('abcdefghikloqstvxyw','@8(63#9#1<1095+>%?','uu'),('ilsvw','!i$<','2u')]:
	for a,b in zip(A,list(B)+[C]):n=n.replace(a,b,1)
print(n)

Çevrimiçi deneyin!


1
Bence düşebilirsin.lower()
mdahmoune

Bu mantıklı, büyük harfle başa çıkmam gerekip gerekmediğinden emin değildim.
reffu



2
Aslında cevabınız çalışmıyor. jjjmjjjjgereken çıkış 3jm4jancak çıkış 3jm3jj. Düzenle: Bu sorunla 258 bayt düzeltildi
NieDzejkob

3

Retina , 166124 bayt

(.)\1+
$.&$1
([a-y])(?<!\1.+)
¶$&
¶w
uu
T`l¶`@8(63#9#1j<\1mn0\p9r5+u>\w%?_`¶.
([ilsvw])(?<!\1.+)
¶$&
¶w
2u
T`i\lsv¶`!i$<_`¶.

Çevrimiçi deneyin! Açıklama:

(.)\1+
$.&$1

Tekrarlanan harflerden oluşan bir diziyi uzunluk ve harfle değiştirin.

([a-y])(?<!\1.+)
¶$&

Harflerin ilk geçtiği Maç aiçin yve bir yer tutucu ile işaretleyin.

¶w
uu

İlk oluşumunu düzeltin w.

T`l¶`@8(63#9#1j<\1mn0\p9r5+u>\w%?_`¶.

Tüm diğer harfler ilk geçtiği Fix aiçin yve tutucuları silin.

([ilsvw])(?<!\1.+)
¶$&

Harflerin (orijinal) ikinci bir örneğini işaretle i, l, s, v, ya da wbir yer tutucu ile.

¶w
2u

İkinci oluşumunu düzeltin w.

T`i\lsv¶`!i$<_`¶.

Diğer dört harfin ikinci oluşumunu düzeltin.


Do you think it’s possible to golf it further?
mdahmoune

@mdahmoune Yes, I think I can save 33 bytes.
Neil

I up-voted your answer :) it will be great if your save the 33 bytes ;)
mdahmoune

@mdahmoune Good news, I actually saved 42 bytes!
Neil

Great, your code is the second shortest ;)
mdahmoune

3

Haskell, 221 218 213 bytes

($(f<$>words"w2u li i! s$ v< a@ b8 c( d6 e3 f# g9 h# i1 k< l1 o0 q9 s5 t+ v> wuu x% y?")++[r]).foldr($)
f(a:b)(h:t)|a==h=b++t|1>0=h:f(a:b)t
f _ s=s
r(a:b)|(p,q)<-span(==a)b=[c|c<-show$1+length p,p>[]]++a:r q
r s=s

Try it online!

Abuses foldr to run the string through a sequence of string transformations backwards. The sequence "starts" with r which does the repetition count replacement by using span to break the tail of the string when it stops being equal to the head. If the first part of that is non-empty it's a repetition so we print the length +1. Next we curry an argument into f for each character replacement in (reverse) order. The replacements are encoded as a single string with the first character being the character to be replaced and the rest as the string (since the w replacements are multiple characters) to go in its place. I put these encoded strings in one big string separated by spaces so that words can break it into a list for me.

EDIT: Thanks @Laikoni for saving me 5 bytes! That was a clever use of $ I didn't think of. I also didn't know that <- trick.


Thanx for detailed explanation ;)
mdahmoune

1
You can use (p,q)<-span(==a)b instead of let(p,q)=span(==a)b and p>[] instead of p/=[].
Laikoni

2
Save two more bytes by making m pointfree: ($(f<$>words"w2u ... y?")++[r]).foldr($) Try it online!
Laikoni

2

Lua, 173 bytes

s=...for c,r in("uua@b8c(d6e3f#g9h#i1i!jjk<l1limmnno0ppq9rrs5s$t+v>v<wuuw2ux%y?zz"):gmatch"(.)(.u?)"do s=s:gsub(c..c.."+",function(p)return#p..c end):gsub(c,r,1)end print(s)

Try it online!

Ungolfed and explained:

s = ...


--This string contains every character to replace, followed by
--the character(s) it should be replaced with.
--
--It also contains all characters for which repeated sequences
--of them should be replaced by "<number><character>". That is,
--all letters in the alphabet. This way, a single loop can do
--both the "replace repeated characters" and "encode characters"
--operations, saving a for loop iterating over the alphabet.
--
--Characters that shouldn't be replaced will be replaced with
--themselves.
--
--In order to avoid matching half of the "replace u with u"
--command as the replace part of another command, "uu" is placed
--at the beginning of the string. This ensures that only the
--2-character replacements for "w" get an extra "u".

cmdstring = "uua@b8c(d6e3f#g9h#i1i!jjk<l1limmnno0ppq9rrs5s$t+v>v<wuuw2ux%y?zz"


--Iterate over all the search/replace commands.
--The character to replace is in the "c" variable, the string to
--replace it with is in "r".
--
--Due to the dummy search/replace commands (i.e. "mm") placed
--in the string, this loop will also iterate over all letters
--of the alphabet.

for c,r in cmdstring:gmatch("(.)(.u?)") do
	
	--First, replace any occurences of the current letter
	--multiple times in a row with "<number><letter>".
	s = s:gsub(c..c.."+", function(p)
		return #p .. c
	end)
	
	--Then, replace the first occurence of the letter
	--with the replacement from the command string.
	s = s:gsub(c, r, 1)
end

print(s)

Lol lua :) good job
mdahmoune

2

C# (.NET Core), 317, 289, 279 Bytes

p=>{string r="",l=r,h=r,c="a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";int i=0,n=p.Length,d,a=1;for(;i<n;i++){h=p[i]+"";if(h==p[(i==n-1?i:i+1)]+""&&i!=n-1)a++;else{d=c.IndexOf(h);if(d>=0&&d%2<1){l=c[d+1]+"";h=l=="u"?"uu":l;c=c.Remove(d,2);}r+=a>1?a+""+h:h;a=1;}}return r;};

Try it Online!

I hope it's ok to receive a char array as an input and not a string.

Ungolfed:

string result = "", casesCharReplacement = result, currentChar = result, cases = "a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";
int i = 0, n = pas.Length, casesIndex, charAmounts = 1;

// For every char in the pass.
for (; i < n; i++)
{
    currentChar = pas[i] + "";
    // if the next char is equal to the current and its not the end of the string then add a +1 to the repeated letter.
    if (currentChar == (pas[(i == n - 1 ? i : i + 1)] + "") && i != n - 1)
        charAmounts++;
    else
    {
        // Finished reading repeated chars (N+Char).
        casesIndex = cases.IndexOf(currentChar);
        // Look for the replacement character: only if the index is an even position, otherwise I could mess up with letters like 'i'.
        if (casesIndex >= 0 && casesIndex % 2 < 1)
        {
            casesCharReplacement = cases[casesIndex + 1]+"";
            // Add the **** +u
            currentChar = casesCharReplacement == "u"?"uu": casesCharReplacement;
            // Remove the 2 replacement characters (ex: a@) as I won't need them anymore.
            cases = cases.Remove(casesIndex, 2);
        }
        // if the amount of letters founded is =1 then only the letter, otherwise number and the letter already replaced with the cases.
        result += charAmounts > 1 ? charAmounts + ""+currentChar : currentChar;
        charAmounts = 1;
    }
}
return result;

1
Yes it’s ok :) for the input
mdahmoune

2

C++, 571 495 478 444 bytes

-127 bytes thanks to Zacharý

#include<string>
#define F r.find(
#define U(S,n)p=F s(S)+b[i]);if(p-size_t(-1)){b.replace(i,1,r.substr(p+n+1,F'/',n+p)-p-2));r.replace(p+1,F'/',p+1)-p,"");}
#define V(A)i<A.size();++i,c
using s=std::string;s m(s a){s b,r="/a@/b8/c(/d6/e3/f#/g9/h#/i1//i!/k</l1//li/o0/q9/s5//s$/t+/v>/wuu//w2u/x%/y?/";int c=1,i=0;for(;V(a)=1){for(;a[i]==a[i+1]&&1+V(a)++);b+=(c-1?std::to_string(c):"")+a[i];}for(i=0;V(b)){auto U("/",1)else{U("//",2)}}return b;}

the "/a@/b8/c(/d6/e3/f#/g9/h#/i1//i!/k</l1//li/o0/q9/s5//s$/t+/v>/wuu//w2u/x%/y?/" string is used to transform from one character to others. 1 / means that the first "next char" should be replaced by what follow the next /, 2 means that the second "next char" should be replaced by what follows.

Try it online


Great, could you please add a tio.run link ?
mdahmoune

@mdahmoune TIO link is added, with the code to test for your test cases :)
HatsuPointerKun

494 bytes, and update the TIO link accordingly if you change it.
Zacharý

@Zacharý You need to put a space between the macro name and the macro content, otherwise, it throws an error when compiling with C++ 17. Also, do you know how to delete a TIO link ? ( since the old one is useless )
HatsuPointerKun


2

R, 224 219 bytes

function(s,K=function(x)el(strsplit(x,"")),u=rle(K(s)))
Reduce(function(x,y)sub(K('abcdefghiiklloqsstvvwwxy')[y],c(K('@8(63#9#1!<1i095$+><'),'uu','2u',K('%?'))[y],x),1:24,paste0(gsub("1","",paste(u$l)),u$v,collapse=""))

Try it online!

Nasty, but the main part is the iterative substitution in the Reduce. sub changes only the first occurrence of the match.

Thanks to JayCe for pointing out a nice golf!


Good job :)))))
mdahmoune

save 1 byte by rearranging args. Doesn't make a huge difference I know ;)
JayCe

@JayCe I found some more bytes :-)
Giuseppe

1

Perl 5, 123 bytes

122 bytes code + 1 for -p.

Developed independently from @Xcali's answer, but using a very similar process.

s/(.)\1+/$&=~y!!!c.$1/ge;eval"s/$1/$2/"while'a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5t+v>v<x%y?'=~/(.)(.)/g;s/s/\$/;s/w/uu/;s;w;2u

Try it online!


1

Python 2, 220 216 194 190 188 bytes

import re
S=re.sub(r'(.)\1+',lambda m:`len(m.group(0))`+m.group(1),input())
for a,b in zip('abcdefghiiklloqsstvvxyww',list('@8(63#9#1!<1i095$+><%?')+['uu','2u']):S=S.replace(a,b,1)
print S

Try it online!

Python 3, 187 bytes

import re
S=re.sub(r'(.)\1+',lambda m:str(len(m.group(0)))+m.group(1),input())
for a,b in zip('abcdefghiiklloqsstvvxyww',[*'@8(63#9#1!<1i095$+><%?','uu','2u']):S=S.replace(a,b,1)
print(S)

Try it online!


Thanx Tfeld 192 bytes tio.run/…
mdahmoune

Great golfing ;)
mdahmoune

186 bytes. You can also easily port this to Python 3 in 192 bytes, but I don't think it should be a separate answer.
NieDzejkob

@NieDzejkob It seems as though your golfed Python 2 version produces a different output than the OP's current version or your Python 3 version.
Jonathan Frech

@JomathanFrech sorry, as always testing on production. 188 bytes
NieDzejkob

1

Pip, 103 102 bytes

aR:`(.)\1+`#_.B
Fm"abcdefghiiklloqsstvvwwxy"Z"@8(63#9#1!<1i095$+><WU%?"I#Ya@?@maRA:ym@1aR'W"uu"R'U"2u"

Try it online!

Explanation

The code does three steps of transformation:

aR:`(.)\1+`#_.B  Process runs of identical letters

a                1st cmdline argument
 R:              Do this replacement and assign back to a:
   `(.)\1+`       This regex (matches 2 or more of same character in a row)
           #_.B   Replace with callback function: concatenate (length of full match) and
                  (first capture group)
                  Note: #_.B is a shortcut form for {#a.b}

Fm"..."Z"..."I#Ya@?@maRA:ym@1  Do the bulk of rules 2-25

  "..."                        String of letters to replace
       Z"..."                  Zip with string of characters to replace with
Fm                             For each m in the zipped list:
                   @m           First item of m is letter to replace
                a@?             Find its index in a, or nil if it isn't in a
               Y                Yank that into y
             I#                 If len of that is truthy:*
                     aRA:        Replace character in a at...
                         y        index y...
                          m@1     with second item of m

aR'W"uu"R'U"2u"  Clean up substitution
                 In the previous step, the replacements each had to be a single character.
                 This doesn't work for uu and 2u, so we use W and U instead (safe, since
                 uppercase letters won't be in the input) and replace them here with the
                 correct substitutions.
aR'W"uu"         In a, replace W with uu
        R'U"2u"  and U with 2u
                 and print the result (implicit)

* We need to test whether a@?m@0 is nil. It's not enough to test that it's truthy, since 0 is a legitimate index that is falsey. Pip doesn't have a short builtin way to test if a value is nil, but testing its length works well enough in this case: any number will have length at least 1 (truthy), and nil has length of nil (falsey).

Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.