Skip to content

Add duplicate elimination option and explicit randomization option #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ const styles = theme => ({
class App extends React.Component {
constructor(props) {
super(props);
this.state = { domain: '', noAscii: false, convertDot: false, weirdChar: false, log: [] };
this.state = {
domain: '',
noAscii: false,
convertDot: false,
weirdChar: false,
log: [],
noDuplicates: false,
randomCharacters: false
};
}

obfuscator(domain) {
Expand All @@ -83,14 +91,22 @@ class App extends React.Component {
}
}

const select = arr => {
arr = arr.filter(char =>
(!this.state.noAscii || char > 0xff)
const select = (arr, denylist) => {
let filteredArr = arr.filter(char =>
(!this.state.noAscii || char > 0xff) && !denylist.includes(String.fromCodePoint(char))
);
return String.fromCodePoint(arr[Math.floor(Math.random() * arr.length)]);
if (filteredArr.length === 0) {
filteredArr = [...arr];
}

const charCode = this.state.randomCharacters ?
filteredArr[Math.floor(Math.random() * filteredArr.length)] :
filteredArr[0];

return String.fromCodePoint(charCode);
}
replace.forEach(r => domain = domain.replace(r, select(mapping[r])));
if (this.state.weirdChar) domain = domain.split("").join(select(mapping[""]));
replace.forEach(r => domain = domain.replace(r, select(mapping[r], (this.state.noDuplicates ? domain : []))));
if (this.state.weirdChar) domain = domain.split("").join(select(mapping[""], (this.state.noDuplicates ? domain : [])));
return domain;
}

Expand Down Expand Up @@ -142,6 +158,14 @@ class App extends React.Component {
control={<Switch color="primary" onChange={e => this.setState({ weirdChar: e.target.checked })} />}
label="Insert Weird Chars"
/>
<FormControlLabel
control={<Switch color="primary" onChange={e => this.setState({ noDuplicates: e.target.checked })} />}
label="No duplicates"
/>
<FormControlLabel
control={<Switch color="primary" onChange={e => this.setState({ randomCharacters: e.target.checked })} />}
label="Random substitution characters"
/>
<Button
type="submit"
fullWidth
Expand Down