Skip to content

Commit

Permalink
fix: flag leet
Browse files Browse the repository at this point in the history
  • Loading branch information
GZTimeWalker committed Sep 11, 2022
1 parent 7ca5205 commit 57d396d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 0 additions & 3 deletions GZCTF/Controllers/TeamController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,6 @@ public async Task<IActionResult> KickUser([FromRoute] int id, [FromRoute] string

try
{
if (team is null)
return BadRequest(new RequestResponse("队伍未找到"));

if (team.Locked && await teamRepository.AnyActiveGame(team, token))
return BadRequest(new RequestResponse("队伍已锁定"));

Expand Down
11 changes: 8 additions & 3 deletions GZCTF/Utils/Codec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,15 @@ public static class Leet
public static double LeetEntropy(string flag)
{
double entropy = 0;
bool doLeet = false;
foreach (char c in flag)
{
if (CharMap.ContainsKey(c))
entropy += Math.Log2(CharMap[c].Length);
if (c == '{' || c == ']')
doLeet = true;
else if (doLeet && (c == '}' || c == '['))
doLeet = false;
else if (doLeet && CharMap.TryGetValue(char.ToUpper(c), out string? table) && table is not null)
entropy += Math.Log(table.Length, 2);
}
return entropy;
}
Expand All @@ -118,7 +123,7 @@ public static string LeetFlag(string original)
continue;
}

sb.Append(c);
sb.Append(c == ' ' ? '_' : c); // replace blank to underline
}

return sb.ToString();
Expand Down

1 comment on commit 57d396d

@Konano
Copy link
Contributor

@Konano Konano commented on 57d396d Sep 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed #38

Please sign in to comment.