huggingface-hub<0.22 import random import re # 1. Unicode 异形映射表 (Homoglyph Mapping) HOMOGLYPH_MAP = { '0': ['0', '𝟢', '𝟘', '𝟎'], '1': ['1', '𝟙', '𝟏', '𝟣'], '2': ['2', '𝟚', '𝟐', '𝟤'], '3': ['3', '𝟛', '𝟑', '𝟥'], '4': ['4', '𝟜', '𝟒', '𝟦'], '5': ['5', '𝟝', '𝟓', '𝟧'], '6': ['6', '𝟞', '𝟔', '𝟨'], '7': ['7', '𝟟', '𝟕', '𝟩'], '8': ['8', '𝟠', '𝟖', '𝟪'], '9': ['9', '𝟡', '𝟗', '𝟫'], 'a': ['a', '𝐚', '𝒂', '𝚊'], 'b': ['b', '𝐛', '𝒃', '𝚋'], 'c': ['c', '𝐜', '𝒄', '𝚌'], '私': ['私'], '信': ['信'], } # 2. 零宽字符 (Invisible Characters) INVISIBLE_CHARS = [ '\u200B', # Zero Width Space '\u200C', # Zero Width Non-Joiner '\u200D', # Zero Width Joiner '\u2060', # Word Joiner ] # 3. 干扰词库 (Noise Injection) NOISE_PHRASES = [ " ", " ", "\n", "✨", "🌈", "🎈", "👋", "📍", "READ MORE", "Details here", "点开看", "防吞", "测试", "ignore this", "sys_check_pass", ".", "..", "..." ] def apply_homoglyphs(text, probability=0.3): result = [] for char in text: lower_char = char.lower() if lower_char in HOMOGLYPH_MAP and random.random() < probability: result.append(random.choice(HOMOGLYPH_MAP[lower_char])) else: result.append(char) return "" .join(result) def inject_invisible_chars(text, intensity=0.3): result=[] for char in text: result.append(char) if random.random() < intensity: for _ in range(random.randint(1, 3)): result.append(random.choice(INVISIBLE_CHARS)) return "" .join(result) def process_spintax(text): pattern=re.compile(r'\{([^{}]*)\}') while True: match=pattern.search(text) if not match: break options=match.group(1).split('|') choice=random.choice(options) text=text[:match.start()] + choice + text[match.end():] return text def inject_noise(text, probability=0.5): if random.random() < probability: noise=random.choice(NOISE_PHRASES) return text + " " + noise return text def obfuscate(text, intensity=0.3, enable_homoglyph=True, enable_noise=True): if not text: return "" text=process_spintax(text) if enable_homoglyph: text=apply_homoglyphs(text, probability=intensity) text=inject_invisible_chars(text, intensity=intensity) if enable_noise: text=inject_noise(text, probability=0.5) return text import gradio as gr from utils import obfuscate def process_text(text, intensity, enable_homoglyph, enable_noise): return obfuscate(text, intensity, enable_homoglyph, enable_noise) with gr.Blocks(title="小红书评论防屏蔽生成器") as demo: gr.Markdown("### 🛡️ 小红书评论防屏蔽生成器 (Antigravity Edition)") gr.Markdown("通过多种混淆技术(同形字符、零宽空格、动态模版)生成的文本,肉眼看起来一样,但这对于算法来说是完全不同的字符串。") with gr.Row(): with gr.Column(scale=1): input_text = gr.Textbox( label="输入固定回复话术", placeholder="例如:私信我领优惠券 {A|B}...", lines=5 ) with gr.Accordion("高级设置", open=True): intensity_slider = gr.Slider( minimum=0.1, maximum=1.0, value=0.3, label="混淆强度 (同形字/零宽字符概率)" ) enable_homoglyph_checkbox = gr.Checkbox(label="启用同形字符替换", value=True) enable_noise_checkbox = gr.Checkbox(label="启用末尾干扰词", value=True) gen_btn = gr.Button("🔥 生成唯一变体", variant="primary") with gr.Column(scale=1): output_text = gr.Textbox( label="混淆后的文本 (直接复制即可)", lines=5, show_copy_button=True ) gr.Markdown(""" > **提示:** > 1. 支持 Spintax 语法 `{A|B|C}` 实现话术轮换。 > 2. 即使文本看起来没变,其底层的 Unicode 编码已完全改变。 > 3. 建议每次回复前都点击生成,获取新的唯一变体。 """) gen_btn.click( fn=process_text, inputs=[input_text, intensity_slider, enable_homoglyph_checkbox, enable_noise_checkbox], outputs=output_text ) demo.launch()